]> granicus.if.org Git - php/commitdiff
Fixed bug #46205 (Closure - Memory leaks when ReflectionException is thrown)
authorDmitry Stogov <dmitry@php.net>
Wed, 1 Oct 2008 07:30:52 +0000 (07:30 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 1 Oct 2008 07:30:52 +0000 (07:30 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug46205.phpt [new file with mode: 0644]

index 2434fae25bffc20d0c9ac59f50b9c96df8c6b509..ae3b802dfaff45cf007c11198030563d55c143ed 100644 (file)
@@ -2005,6 +2005,12 @@ ZEND_METHOD(reflection_parameter, __construct)
        if (Z_TYPE_PP(parameter) == IS_LONG) {
                position= Z_LVAL_PP(parameter);
                if (position < 0 || (zend_uint)position >= fptr->common.num_args) {
+                       if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) {
+                               if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
+                                       efree(fptr->common.function_name.v);
+                               }
+                               efree(fptr);
+                       }
                        _DO_THROW("The parameter specified by its offset could not be found");
                        /* returns out of this function */
                }
@@ -2023,6 +2029,12 @@ ZEND_METHOD(reflection_parameter, __construct)
                        }
                }
                if (position == -1) {
+                       if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) {
+                               if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
+                                       efree(fptr->common.function_name.v);
+                               }
+                               efree(fptr);
+                       }
                        _DO_THROW("The parameter specified by its name could not be found");
                        /* returns out of this function */
                }
diff --git a/ext/reflection/tests/bug46205.phpt b/ext/reflection/tests/bug46205.phpt
new file mode 100644 (file)
index 0000000..ef7a692
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #46205 (Closure - Memory leaks when ReflectionException is thrown)
+--FILE--
+<?php
+$x = new reflectionmethod('reflectionparameter', 'export');
+$y = function() { };
+
+try {
+       $x->invokeArgs(new reflectionparameter('trim', 'str'), array($y, 1));
+} catch (Exception $e) { }
+?>
+ok
+--EXPECT--
+ok