From b6a4094c030c74561b94b2c8004d969719e42d3e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 19 Sep 2008 12:48:33 +0000 Subject: [PATCH] Fixed bug #46115 (Memory leak when calling a method using Reflection) --- NEWS | 2 ++ ext/spl/spl_array.c | 8 ++++++-- ext/spl/tests/bug46115.phpt | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 ext/spl/tests/bug46115.phpt diff --git a/NEWS b/NEWS index fe5401fffb..9302cc523d 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,8 @@ PHP NEWS - Fixed bug causing the algorithm parameter of mhash() to be modified. (Scott) +- Fixed bug #46115 (Memory leak when calling a method using Reflection). + (Dmitry) - Fixed bug #46106 (Memory leaks when using global statement). (Dmitry) - Fixed bug #46099 (Xsltprocessor::setProfiling - memory leak). (Felipe, Rob). - Fixed bug #46087 (DOMXPath - segfault on destruction of a cloned object). diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 14a6553258..fd1fb0759b 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1235,6 +1235,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; @@ -1245,12 +1246,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; } - 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 { - 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); + } } /* }}} */ #define SPL_ARRAY_METHOD(cname, fname, use_arg) \ diff --git a/ext/spl/tests/bug46115.phpt b/ext/spl/tests/bug46115.phpt new file mode 100644 index 0000000000..71207d8a25 --- /dev/null +++ b/ext/spl/tests/bug46115.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #46115 (Memory leak when calling a method using Reflection) +--FILE-- +invoke($h); +?> +DONE +--EXPECT-- +DONE -- 2.40.0