cvs: ZendEngine2(PHP_5_3) / zend_execute_API.c /tests bug46106.phpt php-src NEWS

[email protected] ("Dmitry Stogov")
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1221664289@cvsserver>
dmitry		Wed Sep 17 15:11:29 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /ZendEngine2/tests	bug46106.phpt 

  Modified files:              
    /php-src	NEWS 
    /ZendEngine2	zend_execute_API.c 
  Log:
  Fixed bug #46106 (Memory leaks when using global statement)
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.321&r2=1.2027.2.547.2.965.2.322&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.321 php-src/NEWS:1.2027.2.547.2.965.2.322
--- php-src/NEWS:1.2027.2.547.2.965.2.321	Wed Sep 17 00:20:30 2008
+++ php-src/NEWS	Wed Sep 17 15:11:27 2008
@@ -6,6 +6,7 @@
 - Changed error level E_ERROR into E_WARNING in Soap extension methods 
   parameter validation. (Felipe)
 
+- Fixed bug #46106 (Memory leaks when using global statement). (Dmitry)
 - Fixed bug #46087 (DOMXPath - segfault on destruction of a cloned object).
   (Ilia)
 - Fixed bug #46086 (Segfault when accessing fileinfo class properties).
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.331.2.20.2.24.2.57&r2=1.331.2.20.2.24.2.58&diff_format=u
Index: ZendEngine2/zend_execute_API.c
diff -u ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.57 ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.58
--- ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.57	Mon Sep 15 10:19:53 2008
+++ ZendEngine2/zend_execute_API.c	Wed Sep 17 15:11:28 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.57 2008/09/15 10:19:53 colder Exp $ */
+/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.58 2008/09/17 15:11:28 dmitry Exp $ */
 
 #include <stdio.h>
 #include <signal.h>
@@ -1600,8 +1600,20 @@
 ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
 {
 	zend_uint i;
+	zend_execute_data *ex;
 
 	if (!EG(active_symbol_table)) {
+		
+		/* Search for last called user function */
+		ex = EG(current_execute_data);
+		while (ex && !ex->op_array) {
+			ex = ex->prev_execute_data;
+		}
+		if (ex && ex->symbol_table) {
+			EG(active_symbol_table) = ex->symbol_table;
+			return;
+		}
+
 		if (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
 			/*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
 			EG(active_symbol_table) = *(EG(symtable_cache_ptr)--);
@@ -1610,24 +1622,24 @@
 			zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
 			/*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
 		}
-		if (EG(current_execute_data) && EG(current_execute_data)->op_array) {
-			EG(current_execute_data)->symbol_table = EG(active_symbol_table);
+		if (ex && ex->op_array) {
+			ex->symbol_table = EG(active_symbol_table);
 
-			if (EG(current_execute_data)->op_array->this_var != -1 &&
-			    !EG(current_execute_data)->CVs[EG(current_execute_data)->op_array->this_var] &&
+			if (ex->op_array->this_var != -1 &&
+			    !ex->CVs[ex->op_array->this_var] &&
 			    EG(This)) {
-				EG(current_execute_data)->CVs[EG(current_execute_data)->op_array->this_var] = (zval**)EG(current_execute_data)->CVs + EG(current_execute_data)->op_array->last_var + EG(current_execute_data)->op_array->this_var;
-				*EG(current_execute_data)->CVs[EG(current_execute_data)->op_array->this_var] = EG(This);
+				ex->CVs[ex->op_array->this_var] = (zval**)ex->CVs + ex->op_array->last_var + ex->op_array->this_var;
+				*ex->CVs[ex->op_array->this_var] = EG(This);
  			}
-			for (i = 0; i < EG(current_execute_data)->op_array->last_var; i++) {
-				if (EG(current_execute_data)->CVs[i]) {
+			for (i = 0; i < ex->op_array->last_var; i++) {
+				if (ex->CVs[i]) {
 					zend_hash_quick_update(EG(active_symbol_table),
-						EG(current_execute_data)->op_array->vars[i].name,
-						EG(current_execute_data)->op_array->vars[i].name_len + 1,
-						EG(current_execute_data)->op_array->vars[i].hash_value,
-						(void**)EG(current_execute_data)->CVs[i],
+						ex->op_array->vars[i].name,
+						ex->op_array->vars[i].name_len + 1,
+						ex->op_array->vars[i].hash_value,
+						(void**)ex->CVs[i],
 						sizeof(zval*),
-						(void**)&EG(current_execute_data)->CVs[i]);
+						(void**)&ex->CVs[i]);
 				}
 			}
 		}

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug46106.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug46106.phpt
+++ ZendEngine2/tests/bug46106.phpt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.