]> granicus.if.org Git - php/commitdiff
MFH: fix #39125 (Memleak when reflecting non-existing class/method)
authorAntony Dovgal <tony2001@php.net>
Wed, 11 Oct 2006 15:52:56 +0000 (15:52 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 11 Oct 2006 15:52:56 +0000 (15:52 +0000)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/008.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 5f6bc17c7da562a75643b18214815e6a9a4c4ae9..9a6c08d6ca888feac427b524169cfb2fa029d2a2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,9 +4,10 @@ PHP                                                                        NEWS
 - Fixed bug #38458, PECL bug #8944, PECL bug #7775 (error retrieving
   columns after long/text columns with PDO_ODBC). (Wez)
 - Fixed PECL bug #8816 (issue in php_oci_statement_fetch with more than one 
+  piecewise column) (jeff at badtz-maru dot com, Tony)
 - Fixed PECL bug #7755 (error selecting DOUBLE fields with PDO_ODBC).
   ("slaws", Wez)
-  piecewise column) (jeff at badtz-maru dot com, Tony)
+- Fixed bug #39125 (Memleak when reflecting non-existing class/method). (Tony)
 - Fixed bug #39067 (getDeclaringClass() and private properties). (Tony)
 - Fixed bug #39034 (curl_exec() with return transfer returns TRUE on empty
   files). (Ilia)
index 55189cda8003d6564314ee6292c50929a5ffa9a8..22b134bba8a918a777f5daa0fd0563b247d920af 100644 (file)
@@ -2165,6 +2165,7 @@ ZEND_METHOD(reflection_method, __construct)
                        return;
                }
                if ((tmp = strstr(name_str, "::")) == NULL) {
+                       zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invalid method name %s", name_str); 
                        return;
                }
                classname = &ztmp;
@@ -2186,6 +2187,9 @@ ZEND_METHOD(reflection_method, __construct)
                        if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) {
                                zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
                                                "Class %s does not exist", Z_STRVAL_P(classname)); 
+                               if (classname == &ztmp) {
+                                       zval_dtor(&ztmp);
+                               }
                                return;
                        }
                        ce = *pce;
@@ -2196,6 +2200,9 @@ ZEND_METHOD(reflection_method, __construct)
                        break;
 
                default:
+                       if (classname == &ztmp) {
+                               zval_dtor(&ztmp);
+                       }
                        _DO_THROW("The parameter class is expected to be either a string or an object");
                        /* returns out of this function */
        }
diff --git a/ext/reflection/tests/008.phpt b/ext/reflection/tests/008.phpt
new file mode 100755 (executable)
index 0000000..2abdcdb
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+ReflectionMethod::__construct() tests
+--FILE--
+<?php
+
+$a = array("", 1, "::", "a::", "::b", "a::b");
+
+foreach ($a as $val) {
+       try {
+               new ReflectionMethod($val);
+       } catch (Exception $e) {
+               var_dump($e->getMessage());
+       }
+}
+$a = array("", 1, "");
+$b = array("", "", 1);
+foreach ($a as $key=>$val) {
+       try {
+               new ReflectionMethod($val, $b[$key]);
+       } catch (Exception $e) {
+               var_dump($e->getMessage());
+       }
+}
+
+echo "Done\n";
+?>
+--EXPECTF--    
+string(20) "Invalid method name "
+string(21) "Invalid method name 1"
+string(21) "Class  does not exist"
+string(22) "Class a does not exist"
+string(21) "Class  does not exist"
+string(22) "Class a does not exist"
+string(21) "Class  does not exist"
+string(66) "The parameter class is expected to be either a string or an object"
+string(21) "Class  does not exist"
+Done