Refactor hex_set_symbol function to improve memory management; assigns new value before freeing old value to prevent potential memory issues.
h3rald h3rald@h3rald.com
Thu, 11 Sep 2025 10:02:23 +0200
2 files changed,
6 insertions(+),
4 deletions(-)
M
src/hex.c
→
src/hex.c
@@ -1210,8 +1210,9 @@ {
if (strcmp(entry->key, key) == 0) { // Key already exists, update its value - hex_free_item(ctx, entry->value); // Free old value - entry->value = value; + hex_item_t *old_value = entry->value; + entry->value = value; // Assign new value first + hex_free_item(ctx, old_value); // Then free old value return 0; } entry = entry->next;
M
src/registry.c
→
src/registry.c
@@ -193,8 +193,9 @@ {
if (strcmp(entry->key, key) == 0) { // Key already exists, update its value - hex_free_item(ctx, entry->value); // Free old value - entry->value = value; + hex_item_t *old_value = entry->value; + entry->value = value; // Assign new value first + hex_free_item(ctx, old_value); // Then free old value return 0; } entry = entry->next;