cvs: ZendEngine2 / zend_execute_API.c /tests bug46106.phpt
[email protected] ("Dmitry Stogov")
| Newsgroups | php.zend-engine.cvs |
|---|---|
| Message-ID | <cvsdmitry1221664300@cvsserver> |
dmitry Wed Sep 17 15:11:40 2008 UTC
Modified files:
/ZendEngine2 zend_execute_API.c
/ZendEngine2/tests bug46106.phpt
Log:
Fixed bug #46106 (Memory leaks when using global statement)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.463&r2=1.464&diff_format=u
Index: ZendEngine2/zend_execute_API.c
diff -u ZendEngine2/zend_execute_API.c:1.463 ZendEngine2/zend_execute_API.c:1.464
--- ZendEngine2/zend_execute_API.c:1.463 Mon Sep 15 10:19:14 2008
+++ ZendEngine2/zend_execute_API.c Wed Sep 17 15:11:39 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_execute_API.c,v 1.463 2008/09/15 10:19:14 colder Exp $ */
+/* $Id: zend_execute_API.c,v 1.464 2008/09/17 15:11:39 dmitry Exp $ */
#include <stdio.h>
#include <signal.h>
@@ -1775,8 +1775,20 @@
{
zend_uchar type = ZEND_STR_TYPE;
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)--);
@@ -1785,25 +1797,25 @@
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_u_hash_quick_update(EG(active_symbol_table),
type,
- 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?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug46106.phpt
diff -u /dev/null ZendEngine2/tests/bug46106.phpt:1.2
--- /dev/null Wed Sep 17 15:11:40 2008
+++ ZendEngine2/tests/bug46106.phpt Wed Sep 17 15:11:40 2008
@@ -0,0 +1,22 @@
+--TEST--
+Bug #46106 (Memory leaks when using global statement)
+--FILE--
+<?php
+$foo = array(1);
+
+function foobar($errno, $errstr, $errfile, $errline) { }
+
+set_error_handler('foobar');
+
+function test($x) {
+ global $foo;
+
+ $x->invokeArgs(array(0));
+}
+
+$x = new ReflectionFunction('str_pad');
+test($x);
+?>
+DONE
+--EXPECT--
+DONE