Skip to content

Commit

Permalink
Merge branch 'PHP-5.3' into PHP-5.4
Browse files Browse the repository at this point in the history
* PHP-5.3:
  - Fixed bug #62384 (Attempting to invoke a Closure more than once causes segfaul)
  • Loading branch information
felipensp committed Jun 22, 2012
2 parents af51675 + b8e946b commit 4af92ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,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);

Expand Down
21 changes: 21 additions & 0 deletions ext/reflection/tests/bug62384.phpt
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 4af92ac

Please sign in to comment.