all repos — hex @ bc2cc707d4193e9affbd6f0b1164a4bdf90c92f4

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

Improve memory management in hex_symbol_i and hex_symbol_debug; ensure proper item copying and freeing.
h3rald h3rald@h3rald.com
Wed, 10 Sep 2025 17:29:44 +0200
commit

bc2cc707d4193e9affbd6f0b1164a4bdf90c92f4

parent

28e9f7eb34fddb835342dd113082b302e1be9451

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

jump to
M src/hex.csrc/hex.c

@@ -442,7 +442,9 @@ // Free a token

void hex_free_token(hex_token_t *token) { if (token == NULL) + { return; + } if (token->value) {

@@ -685,7 +687,9 @@

void hex_free_list(hex_context_t *ctx, hex_item_t **quotation, size_t size) { if (!quotation) + { return; + } for (size_t i = 0; i < size; i++) {

@@ -703,7 +707,9 @@

void hex_free_item(hex_context_t *ctx, hex_item_t *item) { if (item == NULL) + { return; + } switch (item->type) {

@@ -1041,7 +1047,9 @@ {

hex_registry_t *registry = ctx->registry; if (!registry) + { return; + } for (size_t i = 0; i < registry->bucket_count; i++) {

@@ -4122,12 +4130,18 @@ return 1;

} for (size_t i = 0; i < item->quotation_size; i++) { - if (hex_push(ctx, item->data.quotation_value[i]) != 0) + hex_item_t *copy = hex_copy_item(ctx, item->data.quotation_value[i]); + if (!copy || hex_push(ctx, copy) != 0) { + if (copy) + { + hex_free_item(ctx, copy); + } HEX_FREE(ctx, item); return 1; } } + HEX_FREE(ctx, item); // free original quotation (no aliasing remains) return 0; }

@@ -4215,13 +4229,19 @@ }

ctx->settings->debugging_enabled = 1; for (size_t i = 0; i < item->quotation_size; i++) { - if (hex_push(ctx, item->data.quotation_value[i]) != 0) + hex_item_t *copy = hex_copy_item(ctx, item->data.quotation_value[i]); + if (!copy || hex_push(ctx, copy) != 0) { + if (copy) + { + hex_free_item(ctx, copy); + } HEX_FREE(ctx, item); ctx->settings->debugging_enabled = 0; return 1; } } + HEX_FREE(ctx, item); ctx->settings->debugging_enabled = 0; return 0; }

@@ -6469,7 +6489,9 @@ hex_item_t *elem_copy = hex_copy_item(ctx, list->data.quotation_value[i]);

if (!elem_copy || hex_push(ctx, elem_copy) != 0) { if (elem_copy) + { hex_free_item(ctx, elem_copy); + } HEX_FREE(ctx, action); HEX_FREE(ctx, list); hex_free_list(ctx, quotation, i);

@@ -6482,7 +6504,9 @@ hex_item_t *act_elem = hex_copy_item(ctx, action->data.quotation_value[j]);

if (!act_elem || hex_push(ctx, act_elem) != 0) { if (act_elem) + { hex_free_item(ctx, act_elem); + } HEX_FREE(ctx, action); HEX_FREE(ctx, list); hex_free_list(ctx, quotation, i);
M src/symbols.csrc/symbols.c

@@ -229,12 +229,18 @@ return 1;

} for (size_t i = 0; i < item->quotation_size; i++) { - if (hex_push(ctx, item->data.quotation_value[i]) != 0) + hex_item_t *copy = hex_copy_item(ctx, item->data.quotation_value[i]); + if (!copy || hex_push(ctx, copy) != 0) { + if (copy) + { + hex_free_item(ctx, copy); + } HEX_FREE(ctx, item); return 1; } } + HEX_FREE(ctx, item); // free original quotation (no aliasing remains) return 0; }

@@ -322,13 +328,19 @@ }

ctx->settings->debugging_enabled = 1; for (size_t i = 0; i < item->quotation_size; i++) { - if (hex_push(ctx, item->data.quotation_value[i]) != 0) + hex_item_t *copy = hex_copy_item(ctx, item->data.quotation_value[i]); + if (!copy || hex_push(ctx, copy) != 0) { + if (copy) + { + hex_free_item(ctx, copy); + } HEX_FREE(ctx, item); ctx->settings->debugging_enabled = 0; return 1; } } + HEX_FREE(ctx, item); ctx->settings->debugging_enabled = 0; return 0; }