Skip to content

Commit 1f6f9c7

Browse files
committed
Fix leak on consteval exception in ReflectionClass::__toString()
1 parent 8bb2f40 commit 1f6f9c7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
373373
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
374374
_class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent));
375375
if (UNEXPECTED(EG(exception))) {
376+
zend_string_release(sub_indent);
376377
return;
377378
}
378379
} ZEND_HASH_FOREACH_END();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Constant evaluation exception during ReflectionClass::__toString()
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
const C = self::UNKNOWN;
8+
}
9+
try {
10+
echo new ReflectionClass(A::class);
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
15+
?>
16+
--EXPECT--
17+
Undefined class constant 'self::UNKNOWN'

0 commit comments

Comments
 (0)