From ce2073832bfe94d5458f61306eadb46e1024e799 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 22 Aug 2022 21:23:24 +0100 Subject: [PATCH] Patched a potential leak --- source/literal_dictionary.c | 15 +++++++++------ source/node.c | 2 -- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/literal_dictionary.c b/source/literal_dictionary.c index e63f1c3..76c0e08 100644 --- a/source/literal_dictionary.c +++ b/source/literal_dictionary.c @@ -8,20 +8,23 @@ //util functions static void setEntryValues(_entry* entry, Literal key, Literal value) { - //free the original string and overwrite it - if (IS_STRING(entry->key)) { + //free the original string/identifier and overwrite it + if (IS_STRING(entry->key) || IS_IDENTIFIER(entry->key)) { freeLiteral(entry->key); } //take ownership of the copied string if (IS_STRING(key)) { - char* buffer = ALLOCATE(char, STRLEN(key) + 1); - strncpy(buffer, AS_STRING(key), STRLEN(key)); - buffer[STRLEN(key)] = '\0'; - entry->key = TO_STRING_LITERAL(buffer); //buffer becomes a part of the key literal + entry->key = TO_STRING_LITERAL( copyString(AS_STRING(key), STRLEN(key)) ); + } + + //OR take ownership of the copied identifier + else if (IS_IDENTIFIER(key)) { + entry->key = TO_IDENTIFIER_LITERAL( copyString(AS_IDENTIFIER(key), STRLEN_I(key)) ); } else { + freeLiteral(entry->key); //for types entry->key = key; } diff --git a/source/node.c b/source/node.c index 8bc2acf..5322c8c 100644 --- a/source/node.c +++ b/source/node.c @@ -79,8 +79,6 @@ void freeNode(Node* node) { freeLiteral(node->increment.identifier); break; } - - FREE(Node, node); } void emitNodeLiteral(Node** nodeHandle, Literal literal) {