cvs: ZendEngine2(PHP_5_2) / zend_compile.c zend_compile.h zend_vm_def.h zend_vm_execute.h /tests bug34065.phpt bug38623.phpt php-src NEWS

From: Date: Tue, 19 Sep 2006 21:36:55 +0000
Subject: cvs: ZendEngine2(PHP_5_2) / zend_compile.c zend_compile.h zend_vm_def.h zend_vm_execute.h /tests bug34065.phpt bug38623.phpt php-src NEWS
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5267@lists.php.net to get a copy of this message
dmitry Tue Sep 19 21:36:55 2006 UTC Added files: (Branch: PHP_5_2) /ZendEngine2/tests bug34065.phpt bug38623.phpt Modified files: /php-src NEWS /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/php-src/NEWS?r1=1.2027.2.547.2.258&r2=1.2027.2.547.2.259&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.258 php-src/NEWS:1.2027.2.547.2.259 --- php-src/NEWS:1.2027.2.547.2.258 Tue Sep 19 20:33:12 2006 +++ php-src/NEWS Tue Sep 19 21:36:53 2006 @@ -6,6 +6,8 @@ (Dmitry) - Fixed bug #38844 (curl_easy_strerror() is defined only since cURL 7.12.0). (Tony) +- Fixed bug #38623 (leaks in a tricky code with switch() and exceptions). + (Dmitry) - Fixed bug #38574 (missing curl constants and improper constant detection). (Ilia) - Fixed bug #37870 (pgo_pgsql tries to de-allocate unused statements). @@ -13,6 +15,7 @@ - Fixed bug #36681 (pdo_pgsql driver incorrectly ignored some errors). (Wez, Ilia) - Fixed bug #34066 (recursive array_walk causes segfault). (Tony) +- Fixed bug #34065 (throw in foreach causes memory leaks). (Dmitry) 14 Sep 2006, PHP 5.2.0RC4 - Added DSA key generation support to openssl_pkey_new(), FR #38731 http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.647.2.27.2.17&r2=1.647.2.27.2.18&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.647.2.27.2.17 ZendEngine2/zend_compile.c:1.647.2.27.2.18 --- ZendEngine2/zend_compile.c:1.647.2.27.2.17 Tue Sep 12 11:01:16 2006 +++ ZendEngine2/zend_compile.c Tue Sep 19 21:36:53 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.647.2.27.2.17 2006/09/12 11:01:16 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.647.2.27.2.18 2006/09/19 21:36:53 dmitry Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -649,6 +649,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.316.2.8.2.5&r2=1.316.2.8.2.6&diff_format=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.316.2.8.2.5 ZendEngine2/zend_compile.h:1.316.2.8.2.6 --- ZendEngine2/zend_compile.h:1.316.2.8.2.5 Mon Jul 24 17:58:32 2006 +++ ZendEngine2/zend_compile.h Tue Sep 19 21:36:53 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.316.2.8.2.5 2006/07/24 17:58:32 helly Exp $ */ +/* $Id: zend_compile.h,v 1.316.2.8.2.6 2006/09/19 21:36:53 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.59.2.29.2.27&r2=1.59.2.29.2.28&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.59.2.29.2.27 ZendEngine2/zend_vm_def.h:1.59.2.29.2.28 --- ZendEngine2/zend_vm_def.h:1.59.2.29.2.27 Mon Sep 18 14:23:52 2006 +++ ZendEngine2/zend_vm_def.h Tue Sep 19 21:36:53 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.59.2.29.2.27 2006/09/18 14:23:52 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.59.2.29.2.28 2006/09/19 21:36:53 dmitry Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -3718,7 +3718,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; @@ -3737,7 +3738,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; + catch_op_num = EX(op_array)->try_catch_array[i].catch_op; + catched = 1; } } @@ -3753,6 +3755,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; @@ -3763,12 +3787,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.62.2.30.2.27&r2=1.62.2.30.2.28&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.62.2.30.2.27 ZendEngine2/zend_vm_execute.h:1.62.2.30.2.28 --- ZendEngine2/zend_vm_execute.h:1.62.2.30.2.27 Mon Sep 18 14:23:52 2006 +++ ZendEngine2/zend_vm_execute.h Tue Sep 19 21:36:53 2006 @@ -528,7 +528,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; @@ -547,7 +548,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; + catch_op_num = EX(op_array)->try_catch_array[i].catch_op; + catched = 1; } } @@ -563,6 +565,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; @@ -573,12 +597,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 (#5267) next »