From 6238291ab3153fbb25ada9b3a0f16e9212e7dd52 Mon Sep 17 00:00:00 2001 From: XOR Date: Thu, 21 Sep 2023 23:39:50 +0200 Subject: [PATCH 1/2] Fix memory leak --- src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.c b/src/main.c index f066cb8..2a4ff11 100755 --- a/src/main.c +++ b/src/main.c @@ -206,6 +206,8 @@ int main(int argc, char **argv) // Cleanup destroy_instruction_information_hashtable(&instruction_informations); shash_destroy_hashtable(&label_table); + free(target_code.buffer); + free(tokens.buffer); return EXIT_SUCCESS; } From 89efb81f3e89243118c2b82947e994f097180943 Mon Sep 17 00:00:00 2001 From: XOR Date: Thu, 21 Sep 2023 23:42:45 +0200 Subject: [PATCH 2/2] Remove print statements used for debugging --- src/labels.c | 2 -- src/main.c | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/labels.c b/src/labels.c index f75c66f..72ae4ef 100644 --- a/src/labels.c +++ b/src/labels.c @@ -12,8 +12,6 @@ void build_label_table(char label_tokens[][MAX_TOKEN_SIZE], shash_hashtable_t *l { if(label_tokens[token_index][0] == '$') { - printf("Found label: %s\n", label_tokens[token_index]+1); - //Store the adress we are at on the heap, as the hashtable only stores pointers to data unsigned int *heap_pointer_to_adress = malloc(sizeof(instruction_index)); *heap_pointer_to_adress = instruction_index; diff --git a/src/main.c b/src/main.c index 2a4ff11..14f93b2 100755 --- a/src/main.c +++ b/src/main.c @@ -143,7 +143,6 @@ int main(int argc, char **argv) shash_hashtable_t label_table; shash_init_hashtable(&label_table, LABEL_TABLE_SIZE); build_label_table((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, &label_table); - printf("Built label table\n"); dynamic_buffer_t no_label_definition_tokens; @@ -155,7 +154,6 @@ int main(int argc, char **argv) } remove_label_definition_tokens((char (*)[MAX_TOKEN_SIZE]) label_tokens.buffer, &no_label_definition_tokens); - printf("Removed label defintions\n"); free(label_tokens.buffer); // Check if the EIPA Assembly contains errors with the no_label_definition_tokens array @@ -171,7 +169,6 @@ int main(int argc, char **argv) return EXIT_FAILURE; } replace_labels_with_adresses((char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens.buffer, &tokens, label_table, instruction_informations); - printf("Removed labels\n"); free(no_label_definition_tokens.buffer); // Generate the target code