com php-src: - Fixed bug #62384 (Attempting to invoke a Closure more than once causes segfaul): ext/reflection/php_reflection.c ext
/reflection/tests/bug62384.phpt
| From: | Felipe Pena | Date: | Fri, 22 Jun 2012 15:05:29 +0000 |
| Subject: | com php-src: - Fixed bug #62384 (Attempting to invoke a Closure more than once causes segfaul): ext/reflection/php_reflection.c ext /reflection/tests/bug62384.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-69428@lists.php.net to get a copy of this message | ||
Commit: b8e946b02eac53f46cbfc8eefb5c91fb5b075c9d
Author: Felipe Pena <felipensp@gmail.com> Fri, 22 Jun 2012 12:05:29 -0300
Parents: 055ecbc62878e86287d742c7246c21606cee8183
Branches: PHP-5.3 PHP-5.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b8e946b02eac53f46cbfc8eefb5c91fb5b075c9d
Log:
- Fixed bug #62384 (Attempting to invoke a Closure more than once causes segfaul)
Bugs:
https://bugs.php.net/62384
Changed paths:
M ext/reflection/php_reflection.c
A ext/reflection/tests/bug62384.phpt
Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index ca90269..966c9a5 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -2747,6 +2747,16 @@ ZEND_METHOD(reflection_method, invokeArgs)
fcc.calling_scope = obj_ce;
fcc.called_scope = intern->ce;
fcc.object_ptr = object;
+
+ /*
+ * Closure::__invoke() actually expects a copy of zend_function, so that it
+ * frees it after the invoking.
+ */
+ if (obj_ce == zend_ce_closure && object &&
+ strlen(mptr->common.function_name) == sizeof(ZEND_INVOKE_FUNC_NAME)-1 &&
+ memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) ==
0) {
+ fcc.function_handler = _copy_function(mptr TSRMLS_CC);
+ }
result = zend_call_function(&fci, &fcc TSRMLS_CC);
diff --git a/ext/reflection/tests/bug62384.phpt b/ext/reflection/tests/bug62384.phpt
new file mode 100644
index 0000000..90a871f
--- /dev/null
+++ b/ext/reflection/tests/bug62384.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #62384 (Attempting to invoke a Closure more than once causes segfaul)
+--FILE--
+<?php
+
+$closure1 = function($val){ return $val; };
+$closure2 = function($val){ return $val; };
+
+$reflection_class = new ReflectionClass($closure1);
+$reflection_method = $reflection_class->getMethod('__invoke');
+
+$arguments1 = array('hello');
+$arguments2 = array('world');
+
+var_dump($reflection_method->invokeArgs($closure1, $arguments1));
+var_dump($reflection_method->invokeArgs($closure2, $arguments2));
+
+?>
+--EXPECT--
+string(5) "hello"
+string(5) "world"