mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Patched a potential leak
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,8 +79,6 @@ void freeNode(Node* node) {
|
||||
freeLiteral(node->increment.identifier);
|
||||
break;
|
||||
}
|
||||
|
||||
FREE(Node, node);
|
||||
}
|
||||
|
||||
void emitNodeLiteral(Node** nodeHandle, Literal literal) {
|
||||
|
||||
Reference in New Issue
Block a user