Patched a potential leak

This commit is contained in:
2022-08-22 21:23:24 +01:00
parent 08e2adab50
commit ce2073832b
2 changed files with 9 additions and 8 deletions

View File

@@ -8,20 +8,23 @@
//util functions //util functions
static void setEntryValues(_entry* entry, Literal key, Literal value) { static void setEntryValues(_entry* entry, Literal key, Literal value) {
//free the original string and overwrite it //free the original string/identifier and overwrite it
if (IS_STRING(entry->key)) { if (IS_STRING(entry->key) || IS_IDENTIFIER(entry->key)) {
freeLiteral(entry->key); freeLiteral(entry->key);
} }
//take ownership of the copied string //take ownership of the copied string
if (IS_STRING(key)) { if (IS_STRING(key)) {
char* buffer = ALLOCATE(char, STRLEN(key) + 1); entry->key = TO_STRING_LITERAL( copyString(AS_STRING(key), STRLEN(key)) );
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 //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 { else {
freeLiteral(entry->key); //for types
entry->key = key; entry->key = key;
} }

View File

@@ -79,8 +79,6 @@ void freeNode(Node* node) {
freeLiteral(node->increment.identifier); freeLiteral(node->increment.identifier);
break; break;
} }
FREE(Node, node);
} }
void emitNodeLiteral(Node** nodeHandle, Literal literal) { void emitNodeLiteral(Node** nodeHandle, Literal literal) {