summaryrefslogtreecommitdiff
path: root/ext/reflection/php_reflection.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-01-16 15:30:24 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-01-16 15:30:24 +0100
commit1fa6f03265467ec1b8b9f898182792ec936dbd74 (patch)
tree12efd15ed7354678377fd066a7cbf857f516cbef /ext/reflection/php_reflection.c
parent1e62e627fd6149d1f5ea7815b155f3dcb59c9476 (diff)
downloadphp-git-1fa6f03265467ec1b8b9f898182792ec936dbd74.tar.gz
Fix reflection leak if type inside type list is resolved
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r--ext/reflection/php_reflection.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 240ea4473c..73ab2b8969 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -231,14 +231,7 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
case REF_TYPE_TYPE:
{
type_reference *type_ref = intern->ptr;
- if (ZEND_TYPE_HAS_LIST(type_ref->type)) {
- void *entry;
- ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(type_ref->type), entry) {
- if (ZEND_TYPE_LIST_IS_NAME(entry)) {
- zend_string_release(ZEND_TYPE_LIST_GET_NAME(entry));
- }
- } ZEND_TYPE_LIST_FOREACH_END();
- } else if (ZEND_TYPE_HAS_NAME(type_ref->type)) {
+ if (ZEND_TYPE_HAS_NAME(type_ref->type)) {
zend_string_release(ZEND_TYPE_NAME(type_ref->type));
}
efree(type_ref);
@@ -1174,16 +1167,12 @@ static void reflection_type_factory(zend_type type, zval *object, zend_bool lega
intern->ptr = reference;
intern->ref_type = REF_TYPE_TYPE;
- /* Property types may be resolved during the lifetime of the ReflectionType,
- * so we need to make sure that the strings we reference are not released. */
- if (ZEND_TYPE_HAS_LIST(type)) {
- void *entry;
- ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(type), entry) {
- if (ZEND_TYPE_LIST_IS_NAME(entry)) {
- zend_string_addref(ZEND_TYPE_LIST_GET_NAME(entry));
- }
- } ZEND_TYPE_LIST_FOREACH_END();
- } else if (ZEND_TYPE_HAS_NAME(type)) {
+ /* Property types may be resolved during the lifetime of the ReflectionType.
+ * If we reference a string, make sure it doesn't get released. However, only
+ * do this for the top-level type, as resolutions inside type lists will be
+ * fully visible to us (we'd have to do a fully copy of the type if we wanted
+ * to prevent that). */
+ if (ZEND_TYPE_HAS_NAME(type)) {
zend_string_addref(ZEND_TYPE_NAME(type));
}
}