start trying to fix memory leaks
This commit is contained in:
@@ -54,6 +54,8 @@ void free_parse_assign(void *ptr) {
|
||||
ParsedValue *parsedValue = ptr;
|
||||
ParsedAssign *parsedAssign = parsedValue->data;
|
||||
free_parsed(parsedAssign->to);
|
||||
free(parsedAssign->to);
|
||||
free_parsed(parsedAssign->from);
|
||||
free(parsedAssign->from);
|
||||
free(parsedAssign);
|
||||
}
|
||||
@@ -4,10 +4,13 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
ParsedValue *convert_to_operation(DArray * to_operate_on, DArray * operations) {
|
||||
if (to_operate_on->size == 1) {
|
||||
return darray_get(to_operate_on, 0);
|
||||
ParsedValue * parsedValue = malloc(sizeof(ParsedValue));
|
||||
memcpy(parsedValue, darray_get(to_operate_on, 0), sizeof(ParsedValue));
|
||||
return parsedValue;
|
||||
}
|
||||
TokenType operation = 0;
|
||||
DArray positions;
|
||||
@@ -68,8 +71,8 @@ ParsedValue *parse_operations(char *file, DArray *tokens, size_t *index,
|
||||
darray_push(&to_operate_on, parse_token_full(file, tokens, index, true, false));
|
||||
}
|
||||
ParsedValue *output = convert_to_operation(&to_operate_on, &operations);
|
||||
darray_free(&to_operate_on, free_parsed);
|
||||
darray_free(&operations, free_parsed);
|
||||
darray_free(&to_operate_on, NULL);
|
||||
darray_free(&operations, NULL);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <gmp.h>
|
||||
|
||||
const char *ValueTypeNames[] = {
|
||||
"string", "assign", "identifier", "number", "if statement", "access",
|
||||
@@ -196,6 +197,8 @@ void free_parsed(void *ptr) {
|
||||
free_parse_access(parsed);
|
||||
break;
|
||||
case AST_NUMBER:
|
||||
mpz_clear(parsed->data);
|
||||
break;
|
||||
case AST_NULL:
|
||||
case AST_BOOLEAN:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user