From 64931fd3c4c7c3d217f2f19c997a8f89779727c5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 7 Jul 2020 11:57:01 +0200 Subject: [PATCH] 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). --- NEWS | 2 ++ Zend/tests/bug79792.phpt | 16 ++++++++++++++++ Zend/zend_hash.c | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/bug79792.phpt diff --git a/NEWS b/NEWS index 279ce98c61..17289b59e0 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ PHP NEWS - Core: . Fixed bug #79778 (Assertion failure if dumping closure with unresolved static variable). (Nikita) + . Fixed bug #79792 (HT iterators not removed if empty array is destroyed). + (Nikita) - COM: . Fixed bug #63208 (BSTR to PHP string conversion not binary safe). (cmb) diff --git a/Zend/tests/bug79792.phpt b/Zend/tests/bug79792.phpt new file mode 100644 index 0000000000..85b98a907b --- /dev/null +++ b/Zend/tests/bug79792.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #79792: HT iterators not removed if empty array is destroyed +--FILE-- + +===DONE=== +--EXPECTF-- +Warning: Invalid argument supplied for foreach() in %s on line %d +===DONE=== diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 16fd24e3dc..2fb0eac448 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1504,11 +1504,11 @@ ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht) } } while (++p != end); } - zend_hash_iterators_remove(ht); - SET_INCONSISTENT(HT_DESTROYED); } else if (EXPECTED(!(HT_FLAGS(ht) & HASH_FLAG_INITIALIZED))) { goto free_ht; } + zend_hash_iterators_remove(ht); + SET_INCONSISTENT(HT_DESTROYED); efree(HT_GET_DATA_ADDR(ht)); free_ht: FREE_HASHTABLE(ht); -- 2.50.0