Added workaround to prevent errors when freeing nested quoations.
h3rald h3rald@h3rald.com
Wed, 21 May 2025 15:31:12 +0200
2 files changed,
9 insertions(+),
3 deletions(-)
M
src/hex.c
→
src/hex.c
@@ -659,6 +659,7 @@ return;
for (size_t i = 0; i < size; i++) { + printf("===> %zu \n", i); if (quotation[i]) { hex_debug(ctx, "FREE: item #%zu", i);@@ -689,7 +690,9 @@
case HEX_TYPE_QUOTATION: if (item->data.quotation_value) { - hex_debug_item(ctx, "FREE", item); + hex_debug(ctx, "FREE: freeing quotation (%zu items)", item->quotation_size); + // Temporarily comment out the free to avoid double free (probably need refcounting instead) + // This happens in case of nested quotations, e.g. a failure in a nested quotation // hex_free_list(ctx, item->data.quotation_value, item->quotation_size); free(item->data.quotation_value); // Free the array of items item->data.quotation_value = NULL; // Set to NULL to avoid double free
M
src/stack.c
→
src/stack.c
@@ -232,6 +232,7 @@ return;
for (size_t i = 0; i < size; i++) { + printf("===> %zu \n", i); if (quotation[i]) { hex_debug(ctx, "FREE: item #%zu", i);@@ -262,8 +263,10 @@
case HEX_TYPE_QUOTATION: if (item->data.quotation_value) { - hex_debug_item(ctx, "FREE", item); - hex_free_list(ctx, item->data.quotation_value, item->quotation_size); + hex_debug(ctx, "FREE: freeing quotation (%zu items)", item->quotation_size); + // Temporarily comment out the free to avoid double free (probably need refcounting instead) + // This happens in case of nested quotations, e.g. a failure in a nested quotation + // hex_free_list(ctx, item->data.quotation_value, item->quotation_size); free(item->data.quotation_value); // Free the array of items item->data.quotation_value = NULL; // Set to NULL to avoid double free }