Skip to content

Commit 0dede83

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix memory leaks in array_any() / array_all()
2 parents 83722a5 + 75cca9f commit 0dede83

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

ext/standard/array.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6629,20 +6629,14 @@ 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())
66376632

6638-
if (UNEXPECTED(EG(exception))) {
6633+
if (UNEXPECTED(Z_ISUNDEF(retval))) {
66396634
return FAILURE;
66406635
}
66416636

66426637
bool retval_true = zend_is_true(&retval);
66436638
zval_ptr_dtor(&retval);
66446639

6645-
<<<<<<< HEAD
66466640
/* This negates the condition, if negate_condition is true. Otherwise it does nothing with `retval_true`. */
66476641
retval_true ^= negate_condition;
66486642

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

66586652
break;
6659-
=======
6660-
if (UNEXPECTED(Z_ISUNDEF(retval))) {
6661-
return FAILURE;
6662-
>>>>>>> 2701b97011 (Fix memory leaks in array_any() / array_all())
66636653
}
66646654
} ZEND_HASH_FOREACH_END();
66656655

ext/standard/tests/array/gh17977.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
array_any() / array_all() leak
3+
--DESCRIPTION--
4+
Found in GH-16831#issuecomment-2700410631
5+
--FILE--
6+
<?php
7+
8+
// Don't touch this str_repeat + random_int combination,
9+
// this is to circumvent SCCP and interning
10+
$key = str_repeat('abc', random_int(3, 3));
11+
12+
var_dump(array_any([$key => 1], static fn () => true));
13+
var_dump(array_all([$key => 1], static fn () => false));
14+
15+
?>
16+
--EXPECT--
17+
bool(true)
18+
bool(false)

0 commit comments

Comments
 (0)