Skip to content

Commit 088e567

Browse files
committed
Fix memory leak
This fixes oss-fuzz #47791
1 parent e864cb6 commit 088e567

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ext/reflection/php_reflection.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -4187,17 +4187,19 @@ ZEND_METHOD(ReflectionClass, getMethod)
41874187
/* }}} */
41884188

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

41964196
if (mptr->common.fn_flags & filter) {
41974197
zval method;
41984198
reflection_method_factory(ce, mptr, NULL, &method);
41994199
add_next_index_zval(retval, &method);
4200+
return 1;
42004201
}
4202+
return 0;
42014203
}
42024204
/* }}} */
42034205

@@ -4237,7 +4239,9 @@ ZEND_METHOD(ReflectionClass, getMethods)
42374239
}
42384240
zend_function *closure = zend_get_closure_invoke_method(obj);
42394241
if (closure) {
4240-
_addmethod(closure, ce, return_value, filter);
4242+
if (!_addmethod(closure, ce, return_value, filter)) {
4243+
_free_function(closure);
4244+
}
42414245
}
42424246
if (!has_obj) {
42434247
zval_ptr_dtor(&obj_tmp);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
ReflectionClass::getMethods()
3+
--FILE--
4+
<?php
5+
$l = function() {};
6+
$o=new ReflectionObject($l);
7+
$o->getMethods(2);
8+
?>
9+
DONE
10+
--EXPECT--
11+
DONE

0 commit comments

Comments
 (0)