Skip to content

Commit c083efb

Browse files
committedSep 26, 2022
Fix memory leak
Fixes oss-fuzz #51622
1 parent b655451 commit c083efb

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎Zend/zend_vm_def.h

+13
Original file line numberDiff line numberDiff line change
@@ -7791,6 +7791,19 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
77917791
*/
77927792
const zend_live_range *range = find_live_range(
77937793
&EX(func)->op_array, throw_op_num, throw_op->op1.var);
7794+
/* free op1 of the corresponding RETURN */
7795+
for (i = throw_op_num; i < range->end; i++) {
7796+
if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE
7797+
|| EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) {
7798+
/* pass */
7799+
} else {
7800+
if (EX(func)->op_array.opcodes[i].opcode == ZEND_RETURN
7801+
&& (EX(func)->op_array.opcodes[i].op1_type & (IS_VAR|IS_TMP_VAR))) {
7802+
zval_ptr_dtor(EX_VAR(EX(func)->op_array.opcodes[i].op1.var));
7803+
}
7804+
break;
7805+
}
7806+
}
77947807
throw_op_num = range->end;
77957808
}
77967809

‎Zend/zend_vm_execute.h

+13
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,19 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_HANDLE_EXCEPTION_SPEC_HANDLER(
29432943
*/
29442944
const zend_live_range *range = find_live_range(
29452945
&EX(func)->op_array, throw_op_num, throw_op->op1.var);
2946+
/* free op1 of the corresponding RETURN */
2947+
for (i = throw_op_num; i < range->end; i++) {
2948+
if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE
2949+
|| EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) {
2950+
/* pass */
2951+
} else {
2952+
if (EX(func)->op_array.opcodes[i].opcode == ZEND_RETURN
2953+
&& (EX(func)->op_array.opcodes[i].op1_type & (IS_VAR|IS_TMP_VAR))) {
2954+
zval_ptr_dtor(EX_VAR(EX(func)->op_array.opcodes[i].op1.var));
2955+
}
2956+
break;
2957+
}
2958+
}
29462959
throw_op_num = range->end;
29472960
}
29482961

0 commit comments

Comments
 (0)