cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_vm_def.h zend_vm_execute.h /tests bug34065.phpt bug38623.phpt

From: Date: Tue, 19 Sep 2006 21:36:00 +0000
Subject: cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_vm_def.h zend_vm_execute.h /tests bug34065.phpt bug38623.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5266@lists.php.net to get a copy of this message
dmitry Tue Sep 19 21:36:00 2006 UTC Added files: /ZendEngine2/tests bug34065.phpt bug38623.phpt Modified files: /ZendEngine2 zend_compile.c zend_compile.h zend_vm_def.h zend_vm_execute.h Log: Fixed bugs #34065 and #38623 (throw in foreach/switch causes memory leaks) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.723&r2=1.724&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.723 ZendEngine2/zend_compile.c:1.724 --- ZendEngine2/zend_compile.c:1.723 Tue Sep 19 10:38:30 2006 +++ ZendEngine2/zend_compile.c Tue Sep 19 21:35:59 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.723 2006/09/19 10:38:30 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.724 2006/09/19 21:35:59 dmitry Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -688,6 +688,7 @@ parent = CG(active_op_array)->current_brk_cont; CG(active_op_array)->current_brk_cont = CG(active_op_array)->last_brk_cont; brk_cont_element = get_next_brk_cont_element(CG(active_op_array)); + brk_cont_element->start = get_next_op_number(CG(active_op_array)); brk_cont_element->parent = parent; } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.h?r1=1.345&r2=1.346&diff_format=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.345 ZendEngine2/zend_compile.h:1.346 --- ZendEngine2/zend_compile.h:1.345 Mon Jul 24 17:51:41 2006 +++ ZendEngine2/zend_compile.h Tue Sep 19 21:35:59 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.345 2006/07/24 17:51:41 helly Exp $ */ +/* $Id: zend_compile.h,v 1.346 2006/09/19 21:35:59 dmitry Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -89,6 +89,7 @@ typedef struct _zend_brk_cont_element { + int start; int cont; int brk; int parent; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h?r1=1.143&r2=1.144&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.143 ZendEngine2/zend_vm_def.h:1.144 --- ZendEngine2/zend_vm_def.h:1.143 Tue Sep 19 10:38:30 2006 +++ ZendEngine2/zend_vm_def.h Tue Sep 19 21:35:59 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.143 2006/09/19 10:38:30 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.144 2006/09/19 21:35:59 dmitry Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -3841,7 +3841,8 @@ { zend_uint op_num = EG(opline_before_exception)-EG(active_op_array)->opcodes; int i; - int encapsulating_block=-1; + zend_uint catch_op_num; + int catched = 0; zval **stack_zval_pp; zval restored_error_reporting; @@ -3860,7 +3861,8 @@ } if (op_num >= EG(active_op_array)->try_catch_array[i].try_op && op_num < EG(active_op_array)->try_catch_array[i].catch_op) { - encapsulating_block = i; + catched = 1; + catch_op_num = EX(op_array)->try_catch_array[i].catch_op; } } @@ -3876,6 +3878,28 @@ zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); } + for (i=0; i<EX(op_array)->last_brk_cont; i++) { + if (EX(op_array)->brk_cont_array[i].start > op_num) { + /* further blocks will not be relevant... */ + break; + } + if (op_num < EX(op_array)->brk_cont_array[i].brk) { + if (!catched || + catch_op_num >= EX(op_array)->brk_cont_array[i].brk) { + zend_op *brk_opline = &EX(op_array)->opcodes[EX(op_array)->brk_cont_array[i].brk]; + + switch (brk_opline->opcode) { + case ZEND_SWITCH_FREE: + zend_switch_free(brk_opline, EX(Ts) TSRMLS_CC); + break; + case ZEND_FREE: + zendi_zval_dtor(EX_T(brk_opline->op1.u.var).tmp_var); + break; + } + } + } + } + /* restore previous error_reporting value */ if (!EG(error_reporting) && EX(old_error_reporting) != NULL && Z_LVAL_P(EX(old_error_reporting)) != 0) { Z_TYPE(restored_error_reporting) = IS_LONG; @@ -3886,12 +3910,12 @@ } EX(old_error_reporting) = NULL; - if (encapsulating_block == -1) { - ZEND_VM_RETURN_FROM_EXECUTE_LOOP(); - } else { - ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[EG(active_op_array)->try_catch_array[encapsulating_block].catch_op]); - ZEND_VM_CONTINUE(); - } + if (!catched) { + ZEND_VM_RETURN_FROM_EXECUTE_LOOP(); + } else { + ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[catch_op_num]); + ZEND_VM_CONTINUE(); + } } ZEND_VM_HANDLER(146, ZEND_VERIFY_ABSTRACT_CLASS, ANY, ANY) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_execute.h?r1=1.147&r2=1.148&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.147 ZendEngine2/zend_vm_execute.h:1.148 --- ZendEngine2/zend_vm_execute.h:1.147 Tue Sep 19 10:38:30 2006 +++ ZendEngine2/zend_vm_execute.h Tue Sep 19 21:35:59 2006 @@ -538,7 +538,8 @@ { zend_uint op_num = EG(opline_before_exception)-EG(active_op_array)->opcodes; int i; - int encapsulating_block=-1; + zend_uint catch_op_num; + int catched = 0; zval **stack_zval_pp; zval restored_error_reporting; @@ -557,7 +558,8 @@ } if (op_num >= EG(active_op_array)->try_catch_array[i].try_op && op_num < EG(active_op_array)->try_catch_array[i].catch_op) { - encapsulating_block = i; + catched = 1; + catch_op_num = EX(op_array)->try_catch_array[i].catch_op; } } @@ -573,6 +575,28 @@ zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); } + for (i=0; i<EX(op_array)->last_brk_cont; i++) { + if (EX(op_array)->brk_cont_array[i].start > op_num) { + /* further blocks will not be relevant... */ + break; + } + if (op_num < EX(op_array)->brk_cont_array[i].brk) { + if (!catched || + catch_op_num >= EX(op_array)->brk_cont_array[i].brk) { + zend_op *brk_opline = &EX(op_array)->opcodes[EX(op_array)->brk_cont_array[i].brk]; + + switch (brk_opline->opcode) { + case ZEND_SWITCH_FREE: + zend_switch_free(brk_opline, EX(Ts) TSRMLS_CC); + break; + case ZEND_FREE: + zendi_zval_dtor(EX_T(brk_opline->op1.u.var).tmp_var); + break; + } + } + } + } + /* restore previous error_reporting value */ if (!EG(error_reporting) && EX(old_error_reporting) != NULL && Z_LVAL_P(EX(old_error_reporting)) != 0) { Z_TYPE(restored_error_reporting) = IS_LONG; @@ -583,12 +607,12 @@ } EX(old_error_reporting) = NULL; - if (encapsulating_block == -1) { - ZEND_VM_RETURN_FROM_EXECUTE_LOOP(); - } else { - ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[EG(active_op_array)->try_catch_array[encapsulating_block].catch_op]); - ZEND_VM_CONTINUE(); - } + if (!catched) { + ZEND_VM_RETURN_FROM_EXECUTE_LOOP(); + } else { + ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[catch_op_num]); + ZEND_VM_CONTINUE(); + } } static int ZEND_VERIFY_ABSTRACT_CLASS_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug34065.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/bug34065.phpt +++ ZendEngine2/tests/bug34065.phpt --TEST-- Bug #34065 (throw in foreach causes memory leaks) --FILE-- <?php $data = file(__FILE__); try { foreach ($data as $line) { throw new Exception("error"); } } catch (Exception $e) { echo "ok\n"; } ?> --EXPECT-- ok http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug38623.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/bug38623.phpt +++ ZendEngine2/tests/bug38623.phpt --TEST-- Bug #38623 (leaks in a tricky code with switch() and exceptions) --FILE-- <?php try { switch(strtolower("apache")) { case "apache": throw new Exception("test"); break; } } catch (Exception $e) { echo "ok\n"; } ?> --EXPECT-- ok

« previous php.zend-engine.cvs (#5266) next »