Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
This fixes oss-fuzz #47791
  • Loading branch information
dstogov committed Jun 6, 2022
1 parent e864cb6 commit 088e567
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ext/reflection/php_reflection.c
Expand Up @@ -4187,17 +4187,19 @@ ZEND_METHOD(ReflectionClass, getMethod)
/* }}} */

/* {{{ _addmethod */
static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter)
static zend_bool _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter)
{
if ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce) {
return;
return 0;
}

if (mptr->common.fn_flags & filter) {
zval method;
reflection_method_factory(ce, mptr, NULL, &method);
add_next_index_zval(retval, &method);
return 1;
}
return 0;
}
/* }}} */

Expand Down Expand Up @@ -4237,7 +4239,9 @@ ZEND_METHOD(ReflectionClass, getMethods)
}
zend_function *closure = zend_get_closure_invoke_method(obj);
if (closure) {
_addmethod(closure, ce, return_value, filter);
if (!_addmethod(closure, ce, return_value, filter)) {
_free_function(closure);
}
}
if (!has_obj) {
zval_ptr_dtor(&obj_tmp);
Expand Down
11 changes: 11 additions & 0 deletions ext/reflection/tests/ReflectionClass_getMethods_004.phpt
@@ -0,0 +1,11 @@
--TEST--
ReflectionClass::getMethods()
--FILE--
<?php
$l = function() {};
$o=new ReflectionObject($l);
$o->getMethods(2);
?>
DONE
--EXPECT--
DONE

0 comments on commit 088e567

Please sign in to comment.