all repos — hex @ 8cf357beabe20eab3195b597f0ef6f644cb586ea

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

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
commit

8cf357beabe20eab3195b597f0ef6f644cb586ea

parent

0702ea148f47b941e9d7ea780cc363f0b581d512

2 files changed, 6 insertions(+), 4 deletions(-)

jump to
M src/hex.csrc/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.csrc/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;