Skip to content

Commit 29b8269

Browse files
committed
Fix leak of callable error if exception also thrown
1 parent c2a8934 commit 29b8269

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Make sure is_callable error does not leak if an exception is also thrown
3+
--FILE--
4+
<?php
5+
spl_autoload_register(function ($class) {
6+
throw new Exception("Failed");
7+
});
8+
try {
9+
array_map('A::b', []);
10+
} catch (Exception $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
?>
14+
--EXPECT--
15+
Failed

Zend/zend_API.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,18 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_or_nu
333333

334334
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(uint32_t num, char *error) /* {{{ */
335335
{
336-
if (EG(exception)) {
337-
return;
336+
if (!EG(exception)) {
337+
zend_argument_type_error(num, "must be a valid callback, %s", error);
338338
}
339-
340-
zend_argument_type_error(num, "must be a valid callback, %s", error);
341339
efree(error);
342340
}
343341
/* }}} */
344342

345343
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_or_null_error(uint32_t num, char *error) /* {{{ */
346344
{
347-
if (EG(exception)) {
348-
return;
345+
if (!EG(exception)) {
346+
zend_argument_type_error(num, "must be a valid callback or null, %s", error);
349347
}
350-
351-
zend_argument_type_error(num, "must be a valid callback or null, %s", error);
352348
efree(error);
353349
}
354350
/* }}} */

0 commit comments

Comments
 (0)