Skip to content

Commit 7451b8b

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix memory leak
2 parents faf3410 + 74744f3 commit 7451b8b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ext/reflection/php_reflection.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4409,17 +4409,19 @@ ZEND_METHOD(ReflectionClass, getMethod)
44094409
/* }}} */
44104410

44114411
/* {{{ _addmethod */
4412-
static void _addmethod(zend_function *mptr, zend_class_entry *ce, HashTable *ht, zend_long filter)
4412+
static bool _addmethod(zend_function *mptr, zend_class_entry *ce, HashTable *ht, zend_long filter)
44134413
{
44144414
if ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce) {
4415-
return;
4415+
return 0;
44164416
}
44174417

44184418
if (mptr->common.fn_flags & filter) {
44194419
zval method;
44204420
reflection_method_factory(ce, mptr, NULL, &method);
44214421
zend_hash_next_index_insert_new(ht, &method);
4422+
return 1;
44224423
}
4424+
return 0;
44234425
}
44244426
/* }}} */
44254427

@@ -4459,7 +4461,9 @@ ZEND_METHOD(ReflectionClass, getMethods)
44594461
}
44604462
zend_function *closure = zend_get_closure_invoke_method(obj);
44614463
if (closure) {
4462-
_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter);
4464+
if (!_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter)) {
4465+
_free_function(closure);
4466+
}
44634467
}
44644468
if (!has_obj) {
44654469
zval_ptr_dtor(&obj_tmp);
Lines changed: 11 additions & 0 deletions
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)