Refactor memory management in symbol functions; ensures proper ownership transfer and prevents memory leaks.
@@ -4009,6 +4009,8 @@ HEX_FREE(ctx, name);
HEX_FREE(ctx, value); return 1; } + // Success: registry takes ownership of 'value'. Free name only. + HEX_FREE(ctx, name); return 0; }@@ -4050,7 +4052,8 @@ HEX_FREE(ctx, name);
HEX_FREE(ctx, value); return 1; } - + // Success: registry now owns 'value'; free only the name item. + HEX_FREE(ctx, name); return 0; }@@ -4081,6 +4084,8 @@ hex_error(ctx, "[symbol #] Symbol not found: %s", item->data.str_value);
HEX_FREE(ctx, item); return 1; } + // Success: free the popped symbol name item + HEX_FREE(ctx, item); return 0; }@@ -4243,6 +4248,7 @@ if (item->type == HEX_TYPE_STRING)
{ int result = hex_interpret(ctx, item->data.str_value, file->data.str_value, 1, 1); HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return result; } else if (item->type == HEX_TYPE_QUOTATION)@@ -4253,6 +4259,7 @@ if (item->data.quotation_value[i]->type != HEX_TYPE_INTEGER)
{ hex_error(ctx, "[symbol !] Quotation must contain only integers"); HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return 1; } }@@ -4273,7 +4280,10 @@ hex_symbol_table_t *symbol_table_copy = hex_symboltable_copy(ctx);
int result = hex_interpret_bytecode(ctx, bytecode, item->quotation_size, file->data.str_value); // Restore the original symbol table ctx->symbol_table = symbol_table_copy; - return result; + free(bytecode); + HEX_FREE(ctx, item); + HEX_FREE(ctx, file); + return result; // NOTE: potential leak of mutated symbol table not restored (pre-existing design) } else {
@@ -44,6 +44,8 @@ HEX_FREE(ctx, name);
HEX_FREE(ctx, value); return 1; } + // Success: registry takes ownership of 'value'. Free name only. + HEX_FREE(ctx, name); return 0; }@@ -85,7 +87,8 @@ HEX_FREE(ctx, name);
HEX_FREE(ctx, value); return 1; } - + // Success: registry now owns 'value'; free only the name item. + HEX_FREE(ctx, name); return 0; }@@ -116,6 +119,8 @@ hex_error(ctx, "[symbol #] Symbol not found: %s", item->data.str_value);
HEX_FREE(ctx, item); return 1; } + // Success: free the popped symbol name item + HEX_FREE(ctx, item); return 0; }@@ -278,6 +283,7 @@ if (item->type == HEX_TYPE_STRING)
{ int result = hex_interpret(ctx, item->data.str_value, file->data.str_value, 1, 1); HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return result; } else if (item->type == HEX_TYPE_QUOTATION)@@ -288,6 +294,7 @@ if (item->data.quotation_value[i]->type != HEX_TYPE_INTEGER)
{ hex_error(ctx, "[symbol !] Quotation must contain only integers"); HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return 1; } }@@ -308,7 +315,10 @@ hex_symbol_table_t *symbol_table_copy = hex_symboltable_copy(ctx);
int result = hex_interpret_bytecode(ctx, bytecode, item->quotation_size, file->data.str_value); // Restore the original symbol table ctx->symbol_table = symbol_table_copy; - return result; + free(bytecode); + HEX_FREE(ctx, item); + HEX_FREE(ctx, file); + return result; // NOTE: potential leak of mutated symbol table not restored (pre-existing design) } else {