From a92a0703531f344885ea2b89dddb6205d18b99a0 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Wed, 11 Oct 2006 15:51:17 +0000 Subject: [PATCH] fix #39125 (Memleak when reflecting non-existing class/method) --- ext/reflection/php_reflection.c | 7 ++++++ ext/reflection/tests/009.phpt | 39 ++++++++++++++++++++++++++++++ ext/reflection/tests/bug39067.phpt | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 ext/reflection/tests/009.phpt diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 26de54bbbf7..62be24aad99 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2180,6 +2180,7 @@ ZEND_METHOD(reflection_method, __construct) } /* FIXME: Unicode support??? */ if ((tmp = strstr(name_str.s, "::")) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invalid method name %s", name_str); return; } type = IS_STRING; @@ -2203,6 +2204,9 @@ ZEND_METHOD(reflection_method, __construct) if (zend_u_lookup_class(Z_TYPE_P(classname), Z_UNIVAL_P(classname), Z_UNILEN_P(classname), &pce TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %v does not exist", Z_UNIVAL_P(classname)); + if (classname == &ztmp) { + zval_dtor(&ztmp); + } return; } ce = *pce; @@ -2213,6 +2217,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/009.phpt b/ext/reflection/tests/009.phpt new file mode 100755 index 00000000000..2abdcdb57b5 --- /dev/null +++ b/ext/reflection/tests/009.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionMethod::__construct() tests +--FILE-- +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 diff --git a/ext/reflection/tests/bug39067.phpt b/ext/reflection/tests/bug39067.phpt index 71e859a2c77..5aae0831523 100644 --- a/ext/reflection/tests/bug39067.phpt +++ b/ext/reflection/tests/bug39067.phpt @@ -47,5 +47,5 @@ Done unicode(1) "C" unicode(1) "B" unicode(1) "A" -unicode(4) "Test2" +unicode(5) "Test2" Done