Skip to content

Commit 3b853c9

Browse files
committed
Fixed bug #80045
Applying the obvious fix ... however, I think we may need to rething how we handle trampoline fcc for "f" zpp. It might make sense to use fcc->function_handler == NULL for that case and force it to be fetched in zend_call_function instead (it will be reset to that after the call anyway). Otherwise we will keep chasing these leaks, as it's the only instance where it's necessary to free a zpp result.
1 parent daf222c commit 3b853c9

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Implement #[Attr] Attribute syntax as per final vote in RFC
77
https://wiki.php.net/rfc/shorter_attribute_syntax_change
8+
. Fixed bug #80045 (memleak after two set_exception_handler calls with
9+
__call). (Nikita)
810

911
03 Sep 2020, PHP 8.0.0beta3
1012

Zend/tests/bug80045.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #80045: memleak after two set_exception_handler calls with __call
3+
--FILE--
4+
<?php
5+
6+
class x {
7+
public function __construct(){
8+
set_exception_handler([$this, 'dummyExceptionHandler']);
9+
set_exception_handler([$this, 'dummyExceptionHandler']);
10+
set_error_handler([$this, 'dummyErrorHandler']);
11+
set_error_handler([$this, 'dummyErrorHandler']);
12+
}
13+
14+
public function __call($m, $p) {}
15+
}
16+
17+
new x;
18+
19+
?>
20+
===DONE===
21+
--EXPECT--
22+
===DONE===

Zend/zend_builtin_functions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ ZEND_FUNCTION(set_error_handler)
11981198

11991199
ZVAL_COPY(&EG(user_error_handler), &(fci.function_name));
12001200
EG(user_error_handler_error_reporting) = (int)error_type;
1201+
zend_release_fcall_info_cache(&fcc);
12011202
}
12021203
/* }}} */
12031204

@@ -1253,6 +1254,7 @@ ZEND_FUNCTION(set_exception_handler)
12531254
}
12541255

12551256
ZVAL_COPY(&EG(user_exception_handler), &(fci.function_name));
1257+
zend_release_fcall_info_cache(&fcc);
12561258
}
12571259
/* }}} */
12581260

0 commit comments

Comments
 (0)