Skip to content

Commit 64931fd

Browse files
committed
Fixed bug #79792
We need to remove the iterators even if the array is empty (we will not create one if the first place, but the array may become empty after the fact).
1 parent b765f96 commit 64931fd

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
- Core:
1010
. Fixed bug #79778 (Assertion failure if dumping closure with unresolved
1111
static variable). (Nikita)
12+
. Fixed bug #79792 (HT iterators not removed if empty array is destroyed).
13+
(Nikita)
1214

1315
- COM:
1416
. Fixed bug #63208 (BSTR to PHP string conversion not binary safe). (cmb)

Zend/tests/bug79792.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #79792: HT iterators not removed if empty array is destroyed
3+
--FILE--
4+
<?php
5+
$a = [42];
6+
foreach ($a as &$c) {
7+
// Make the array empty.
8+
unset($a[0]);
9+
// Destroy the array.
10+
$a = null;
11+
}
12+
?>
13+
===DONE===
14+
--EXPECTF--
15+
Warning: Invalid argument supplied for foreach() in %s on line %d
16+
===DONE===

Zend/zend_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,11 +1504,11 @@ ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
15041504
}
15051505
} while (++p != end);
15061506
}
1507-
zend_hash_iterators_remove(ht);
1508-
SET_INCONSISTENT(HT_DESTROYED);
15091507
} else if (EXPECTED(!(HT_FLAGS(ht) & HASH_FLAG_INITIALIZED))) {
15101508
goto free_ht;
15111509
}
1510+
zend_hash_iterators_remove(ht);
1511+
SET_INCONSISTENT(HT_DESTROYED);
15121512
efree(HT_GET_DATA_ADDR(ht));
15131513
free_ht:
15141514
FREE_HASHTABLE(ht);

0 commit comments

Comments
 (0)