]> granicus.if.org Git - php/commitdiff
Fixed bug #46115 (Memory leak when calling a method using Reflection)
authorDmitry Stogov <dmitry@php.net>
Fri, 19 Sep 2008 12:48:45 +0000 (12:48 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 19 Sep 2008 12:48:45 +0000 (12:48 +0000)
ext/spl/spl_array.c
ext/spl/tests/bug46115.phpt [new file with mode: 0644]

index 22afbb92fefafe6b257acb84541cc5162494db9e..6f0bda0e2e8ad9d72c3da830ba3bf38e63957058 100755 (executable)
@@ -1230,6 +1230,7 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam
        spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
        HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
        zval *tmp, *arg;
+       zval *retval_ptr = NULL;
        
        MAKE_STD_ZVAL(tmp);
        Z_TYPE_P(tmp) = IS_ARRAY;
@@ -1240,14 +1241,15 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam
                        zend_throw_exception(spl_ce_BadMethodCallException, "Function expects exactly one argument", 0 TSRMLS_CC);
                        return;
                }
-               zval_ptr_dtor(return_value_ptr);
-               zend_call_method(NULL, NULL, NULL, fname, fname_len, return_value_ptr, 2, tmp, arg TSRMLS_CC);
+               zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval_ptr, 2, tmp, arg TSRMLS_CC);
        } else {
-               zval_ptr_dtor(return_value_ptr);
-               zend_call_method(NULL, NULL, NULL, fname, fname_len, return_value_ptr, 1, tmp, NULL TSRMLS_CC);
+               zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval_ptr, 1, tmp, NULL TSRMLS_CC);
        }
        Z_TYPE_P(tmp) = IS_NULL; /* we want to destroy the zval, not the hashtable */
        zval_ptr_dtor(&tmp);
+       if (retval_ptr) {
+               COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
+       }
 } /* }}} */
 
 /* {{{ SPL_ARRAY_METHOD */
diff --git a/ext/spl/tests/bug46115.phpt b/ext/spl/tests/bug46115.phpt
new file mode 100644 (file)
index 0000000..71207d8
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #46115 (Memory leak when calling a method using Reflection)
+--FILE--
+<?php
+$h = new RecursiveArrayIterator(array());
+$x = new reflectionmethod('RecursiveArrayIterator', 'asort');
+$z = $x->invoke($h);
+?>
+DONE
+--EXPECT--
+DONE