From: Dmitry Stogov Date: Fri, 19 Sep 2008 12:48:45 +0000 (+0000) Subject: Fixed bug #46115 (Memory leak when calling a method using Reflection) X-Git-Tag: BEFORE_HEAD_NS_CHANGE~353 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=063c29f9ce0755f69cf1146545bd69ebe726e28d;p=php Fixed bug #46115 (Memory leak when calling a method using Reflection) --- diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 22afbb92fe..6f0bda0e2e 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -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 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