Skip to content

Memory leak in brainfuck_parse_character #90

Description

@Evanuw

It seems like if the brainfuck token does not exists,
the space allocated by the malloc will be lost forever (memory leak !)

BrainfuckInstruction * brainfuck_parse_character(char c) {

    // put this AFTER the switch
BrainfuckInstruction *instruction = (BrainfuckInstruction *) malloc(sizeof(BrainfuckInstruction)); 
instruction->next = 0;
instruction->loop = 0;
instruction->difference = 1;


switch(c) {
case BRAINFUCK_TOKEN_PLUS:
case BRAINFUCK_TOKEN_MINUS:
case BRAINFUCK_TOKEN_NEXT:
case BRAINFUCK_TOKEN_PREVIOUS:
case BRAINFUCK_TOKEN_OUTPUT:
case BRAINFUCK_TOKEN_INPUT:
case BRAINFUCK_TOKEN_LOOP_START:
case BRAINFUCK_TOKEN_LOOP_END:
case BRAINFUCK_TOKEN_BREAK:
	break;
default:
	return NULL; 
}
instruction->type = c;
return instruction;

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions