summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--ext/standard/array.c1
-rw-r--r--ext/standard/tests/array/bug76778.phpt26
3 files changed, 29 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 3119eb5ce2..b53d50f8c1 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@ PHP NEWS
Siebels)
- Standard:
+ . Fixed bug #76778 (array_reduce leaks memory if callback throws exception).
+ (cmb)
. Fixed bug #76755 (setcookie does not accept "double" type for expire time).
(Laruence)
. Fixed bug #76674 (improve array_* failure messages exposing what was passed
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 1049ec1fce..8ada2c4d8f 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -5994,6 +5994,7 @@ PHP_FUNCTION(array_reduce)
} else {
zval_ptr_dtor(&args[1]);
zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&result);
return;
}
} ZEND_HASH_FOREACH_END();
diff --git a/ext/standard/tests/array/bug76778.phpt b/ext/standard/tests/array/bug76778.phpt
new file mode 100644
index 0000000000..2c65497d12
--- /dev/null
+++ b/ext/standard/tests/array/bug76778.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #76778 (array_reduce leaks memory if callback throws exception)
+--SKIPIF--
+<?php
+if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
+?>
+--INI--
+memory_limit=32M
+--FILE--
+<?php
+for ($i = 0; $i < 100; $i++) {
+ try {
+ array_reduce(
+ [1],
+ function ($carry, $item) {
+ throw new Exception;
+ },
+ range(1, 200000)
+ );
+ } catch (Exception $e) {
+ }
+}
+?>
+===DONE===
+--EXPECT--
+===DONE===