Minor fixes to registry memory management.
h3rald h3rald@h3rald.com
Wed, 10 Sep 2025 17:22:18 +0200
2 files changed,
12 insertions(+),
12 deletions(-)
M
src/hex.c
→
src/hex.c
@@ -1189,17 +1189,17 @@ while (entry != NULL)
{ if (strcmp(entry->key, key) == 0) { - // Key found, copy the value to result - HEX_ALLOC(item); - item = hex_copy_item(ctx, entry->value); // Copy the value structure - if (item == NULL) + // Deep copy registry value into caller-provided storage (no aliasing) + hex_item_t *copy = hex_copy_item(ctx, entry->value); + if (!copy) { hex_error(ctx, "[get symbol] Failed to copy item for key: %s", key); return 0; } - *result = *item; + *result = *copy; // Move struct contents + free(copy); // Free wrapper; inner allocations now owned by result hex_debug_item(ctx, "DONE", result); - return 1; // Success + return 1; } entry = entry->next; // Move to the next entry in the bucket }
M
src/registry.c
→
src/registry.c
@@ -226,17 +226,17 @@ while (entry != NULL)
{ if (strcmp(entry->key, key) == 0) { - // Key found, copy the value to result - HEX_ALLOC(item); - item = hex_copy_item(ctx, entry->value); // Copy the value structure - if (item == NULL) + // Deep copy registry value into caller-provided storage (no aliasing) + hex_item_t *copy = hex_copy_item(ctx, entry->value); + if (!copy) { hex_error(ctx, "[get symbol] Failed to copy item for key: %s", key); return 0; } - *result = *item; + *result = *copy; // Move struct contents + free(copy); // Free wrapper; inner allocations now owned by result hex_debug_item(ctx, "DONE", result); - return 1; // Success + return 1; } entry = entry->next; // Move to the next entry in the bucket }