Skip to content

Commit 83722a5

Browse files
committed
Fix memory leaks in array_any() / array_all()
The return value is overwritten, but if the key was not an interned string we should destroy it. Closes GH-17977.
1 parent eebc7b0 commit 83722a5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

ext/standard/array.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -6629,6 +6629,11 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
66296629

66306630
zend_result result = zend_call_function(&fci, &fci_cache);
66316631
ZEND_ASSERT(result == SUCCESS);
6632+
<<<<<<< HEAD
6633+
=======
6634+
if (EXPECTED(!Z_ISUNDEF(retval))) {
6635+
int retval_true;
6636+
>>>>>>> 2701b97011 (Fix memory leaks in array_any() / array_all())
66326637

66336638
if (UNEXPECTED(EG(exception))) {
66346639
return FAILURE;
@@ -6637,6 +6642,7 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
66376642
bool retval_true = zend_is_true(&retval);
66386643
zval_ptr_dtor(&retval);
66396644

6645+
<<<<<<< HEAD
66406646
/* This negates the condition, if negate_condition is true. Otherwise it does nothing with `retval_true`. */
66416647
retval_true ^= negate_condition;
66426648

@@ -6650,6 +6656,10 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
66506656
}
66516657

66526658
break;
6659+
=======
6660+
if (UNEXPECTED(Z_ISUNDEF(retval))) {
6661+
return FAILURE;
6662+
>>>>>>> 2701b97011 (Fix memory leaks in array_any() / array_all())
66536663
}
66546664
} ZEND_HASH_FOREACH_END();
66556665

@@ -6717,7 +6727,11 @@ PHP_FUNCTION(array_any)
67176727
RETURN_THROWS();
67186728
}
67196729

6720-
RETURN_BOOL(Z_TYPE_P(return_value) != IS_UNDEF);
6730+
bool retval = !Z_ISUNDEF_P(return_value);
6731+
if (Z_TYPE_P(return_value) == IS_STRING) {
6732+
zval_ptr_dtor_str(return_value);
6733+
}
6734+
RETURN_BOOL(retval);
67216735
}
67226736
/* }}} */
67236737

@@ -6737,7 +6751,11 @@ PHP_FUNCTION(array_all)
67376751
RETURN_THROWS();
67386752
}
67396753

6740-
RETURN_BOOL(Z_TYPE_P(return_value) == IS_UNDEF);
6754+
bool retval = Z_ISUNDEF_P(return_value);
6755+
if (Z_TYPE_P(return_value) == IS_STRING) {
6756+
zval_ptr_dtor_str(return_value);
6757+
}
6758+
RETURN_BOOL(retval);
67416759
}
67426760
/* }}} */
67436761

0 commit comments

Comments
 (0)