From 1f6f9c70cb4e82ca9fbbf3153173e3d73a0f9170 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 31 Aug 2020 15:10:09 +0200 Subject: [PATCH] Fix leak on consteval exception in ReflectionClass::__toString() --- ext/reflection/php_reflection.c | 1 + .../tests/ReflectionClass_toString_004.phpt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 ext/reflection/tests/ReflectionClass_toString_004.phpt diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index df00e5b4ba..620d95afa4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -373,6 +373,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) { _class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent)); if (UNEXPECTED(EG(exception))) { + zend_string_release(sub_indent); return; } } ZEND_HASH_FOREACH_END(); diff --git a/ext/reflection/tests/ReflectionClass_toString_004.phpt b/ext/reflection/tests/ReflectionClass_toString_004.phpt new file mode 100644 index 0000000000..04b42d0792 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_004.phpt @@ -0,0 +1,17 @@ +--TEST-- +Constant evaluation exception during ReflectionClass::__toString() +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +Undefined class constant 'self::UNKNOWN' -- 2.50.0