mirror of
https://github.com/php/php-src.git
synced 2024-11-24 10:24:11 +08:00
Fixed bug #67856 (Leak when using array_reduce with by-ref function)
This commit is contained in:
parent
29a8701389
commit
0f5bad93fd
11
Zend/tests/bug67856.phpt
Normal file
11
Zend/tests/bug67856.phpt
Normal file
@ -0,0 +1,11 @@
|
||||
--TEST--
|
||||
Bug #67856 (Leak when using array_reduce with by-ref function)
|
||||
--FILE--
|
||||
<?php
|
||||
$array = [1, 2, 3];
|
||||
var_dump(array_reduce($array, function(&$a, &$b) {
|
||||
return $a + $b;
|
||||
}, 0));
|
||||
?>
|
||||
--EXPECT--
|
||||
int(6)
|
@ -4298,14 +4298,18 @@ PHP_FUNCTION(array_reduce)
|
||||
fci.no_separation = 0;
|
||||
|
||||
ZEND_HASH_FOREACH_VAL(htbl, operand) {
|
||||
ZVAL_COPY_VALUE(&args[0], &result);
|
||||
ZVAL_COPY_VALUE(&args[1], operand);
|
||||
ZVAL_COPY(&args[0], &result);
|
||||
ZVAL_COPY(&args[1], operand);
|
||||
fci.params = args;
|
||||
|
||||
if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
|
||||
zval_ptr_dtor(&args[1]);
|
||||
zval_ptr_dtor(&args[0]);
|
||||
zval_ptr_dtor(&result);
|
||||
ZVAL_COPY_VALUE(&result, &retval);
|
||||
} else {
|
||||
zval_ptr_dtor(&args[1]);
|
||||
zval_ptr_dtor(&args[0]);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback");
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user