mirror of
https://github.com/json-c/json-c.git
synced 2026-04-26 23:59:06 +08:00
Issue #923: Avoid stack recursion in json_object_put() so heavily nested object trees can be freed.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user