Skip to content

Commit 5ad8b3b

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix memory leak
2 parents 8c20ad1 + b20568d commit 5ad8b3b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Live range & free on return & TMP var of RETURN opcode
3+
--FILE--
4+
<?php
5+
class bar{
6+
public $y;
7+
function __destruct() {
8+
y;
9+
}
10+
}
11+
foreach(new bar as $y) {
12+
try {
13+
return new Exception;
14+
} catch(y) {
15+
}
16+
}
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught Error: Undefined constant "y" in %stemporary_cleaning_017.php:5
20+
Stack trace:
21+
#0 %stemporary_cleaning_017.php(10): bar->__destruct()
22+
#1 {main}
23+
thrown in %stemporary_cleaning_017.php on line 5

Zend/zend_vm_def.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7922,6 +7922,19 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
79227922
*/
79237923
const zend_live_range *range = find_live_range(
79247924
&EX(func)->op_array, throw_op_num, throw_op->op1.var);
7925+
/* free op1 of the corresponding RETURN */
7926+
for (i = throw_op_num; i < range->end; i++) {
7927+
if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE
7928+
|| EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) {
7929+
/* pass */
7930+
} else {
7931+
if (EX(func)->op_array.opcodes[i].opcode == ZEND_RETURN
7932+
&& (EX(func)->op_array.opcodes[i].op1_type & (IS_VAR|IS_TMP_VAR))) {
7933+
zval_ptr_dtor(EX_VAR(EX(func)->op_array.opcodes[i].op1.var));
7934+
}
7935+
break;
7936+
}
7937+
}
79257938
throw_op_num = range->end;
79267939
}
79277940

Zend/zend_vm_execute.h

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)