Skip to content

Commit c5e8c98

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix leak when setting cyclic previous exception in finally
2 parents e93d20a + 0fa70b3 commit c5e8c98

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Leak when setting recursive previous exception in finally handling
3+
--FILE--
4+
<?php
5+
6+
try {
7+
try {
8+
throw new Exception("Test");
9+
} catch (Exception $e) {
10+
throw $e;
11+
} finally {
12+
throw $e;
13+
}
14+
} catch (Exception $e2) {
15+
echo $e2->getMessage(), "\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
Test

Zend/zend_exceptions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo
8181
zval pv, zv, rv;
8282
zend_class_entry *base_ce;
8383

84-
if (exception == add_previous || !add_previous || !exception) {
84+
if (!exception || !add_previous) {
8585
return;
8686
}
8787

88-
if (zend_is_unwind_exit(add_previous)) {
88+
if (exception == add_previous || zend_is_unwind_exit(add_previous)) {
8989
OBJ_RELEASE(add_previous);
9090
return;
9191
}

0 commit comments

Comments
 (0)