Skip to content

Commit 2d750ad

Browse files
Fix memory leaks: remove spurious GC_TRY_ADDREF on transferred arrays
dc_build_output transferred entry->props and entry->prop_mask into the states array by setting e->props = NULL to prevent double-free. But it also called GC_TRY_ADDREF which bumped the refcount to 2, leaving 1 after the states dtor freed its reference — leaking the HashTable. The arrays are moved, not shared, so no addref is needed.
1 parent 09a26c2 commit 2d750ad

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

deepclone.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,15 +1494,14 @@ static void dc_build_output(dc_ctx *ctx, zval *prepared, zval *top_mask, zval *r
14941494
ZVAL_LONG(&zid, id);
14951495
zend_hash_index_add_new(Z_ARRVAL(states), (zend_ulong)e->wakeup, &zid);
14961496
} else if (e->wakeup < 0) {
1497+
/* Transfer ownership of props/prop_mask to the states array. */
14971498
zval state_entry;
14981499
if (e->prop_mask) {
14991500
array_init_size(&state_entry, 3);
15001501
zval zid, zprops, zmask;
15011502
ZVAL_LONG(&zid, id);
15021503
ZVAL_ARR(&zprops, e->props);
1503-
GC_TRY_ADDREF(e->props);
15041504
ZVAL_ARR(&zmask, e->prop_mask);
1505-
GC_TRY_ADDREF(e->prop_mask);
15061505
zend_hash_index_add_new(Z_ARRVAL(state_entry), 0, &zid);
15071506
zend_hash_index_add_new(Z_ARRVAL(state_entry), 1, &zprops);
15081507
zend_hash_index_add_new(Z_ARRVAL(state_entry), 2, &zmask);
@@ -1511,7 +1510,6 @@ static void dc_build_output(dc_ctx *ctx, zval *prepared, zval *top_mask, zval *r
15111510
zval zid, zprops;
15121511
ZVAL_LONG(&zid, id);
15131512
ZVAL_ARR(&zprops, e->props);
1514-
GC_TRY_ADDREF(e->props);
15151513
zend_hash_index_add_new(Z_ARRVAL(state_entry), 0, &zid);
15161514
zend_hash_index_add_new(Z_ARRVAL(state_entry), 1, &zprops);
15171515
}

0 commit comments

Comments
 (0)