Issue #923: Avoid stack recursion in json_object_put() so heavily nested object trees can be freed.

This commit is contained in:
Eric Hawicz
2026-04-24 12:56:40 -04:00
parent fe30bc7e66
commit 96a2496fc3
4 changed files with 168 additions and 15 deletions

View File

@@ -668,6 +668,8 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
/* CAW: fixed to be 64bit nice, still need the crazy negative case... */
ptrdiff_t n = (ptrdiff_t)(e - t->table);
assert(n >= 0 && n < t->size);
/* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */
if (n < 0)
{
@@ -709,10 +711,14 @@ int lh_table_delete_entry_to_tail(struct lh_table *t, struct lh_entry *first_ent
struct lh_entry *del_entry = t->tail;
do
{
struct lh_entry *prev = del_entry->prev;
// Could probably micro-optimize this, but better to avoid code duplication for now
if (lh_table_delete_entry(t, del_entry) != 0)
return -1;
} while (del_entry != first_entry);
if (del_entry == first_entry)
break;
del_entry = prev;
} while (del_entry != NULL);
return 0;
}