all repos — hex @ 3ffeee3fb4f0e0a57a4b47c81baef6200d8002fe

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

Fixes.
h3rald h3rald@h3rald.com
Sun, 29 Dec 2024 16:50:24 +0100
commit

3ffeee3fb4f0e0a57a4b47c81baef6200d8002fe

parent

ebb16a0bd544defc76bef8b6e7bde9a27e40e51e

1 files changed, 7 insertions(+), 1 deletions(-)

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

@@ -149,15 +149,21 @@ for (size_t i = 0; i < ctx->registry->size; i++)

{ if (strcmp(ctx->registry->entries[i]->key, item->data.str_value) == 0) { + // Free the memory associated with this entry free(ctx->registry->entries[i]->key); HEX_FREE(ctx, ctx->registry->entries[i]->value); + // Shift entries down to fill the gap for (size_t j = i; j < ctx->registry->size - 1; j++) { ctx->registry->entries[j] = ctx->registry->entries[j + 1]; } + // Clear the last entry to avoid dangling pointers + ctx->registry->entries[ctx->registry->size - 1] = NULL; + // Decrement the registry size ctx->registry->size--; + // Free the `item` as it is no longer needed HEX_FREE(ctx, item); - return 0; + return 0; // Exit after removing the entry } } HEX_FREE(ctx, item);