Skip to content

Commit 74744f3

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix memory leak
2 parents b86c624 + 088e567 commit 74744f3

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
@@ -4377,17 +4377,19 @@ ZEND_METHOD(ReflectionClass, getMethod)
43774377
/* }}} */
43784378

43794379
/* {{{ _addmethod */
4380-
static void _addmethod(zend_function *mptr, zend_class_entry *ce, HashTable *ht, zend_long filter)
4380+
static bool _addmethod(zend_function *mptr, zend_class_entry *ce, HashTable *ht, zend_long filter)
43814381
{
43824382
if ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce) {
4383-
return;
4383+
return 0;
43844384
}
43854385

43864386
if (mptr->common.fn_flags & filter) {
43874387
zval method;
43884388
reflection_method_factory(ce, mptr, NULL, &method);
43894389
zend_hash_next_index_insert_new(ht, &method);
4390+
return 1;
43904391
}
4392+
return 0;
43914393
}
43924394
/* }}} */
43934395

@@ -4427,7 +4429,9 @@ ZEND_METHOD(ReflectionClass, getMethods)
44274429
}
44284430
zend_function *closure = zend_get_closure_invoke_method(obj);
44294431
if (closure) {
4430-
_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter);
4432+
if (!_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter)) {
4433+
_free_function(closure);
4434+
}
44314435
}
44324436
if (!has_obj) {
44334437
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)