Skip to content

Commit 29e861b

Browse files
committed
adds zend_type_release_internal()
1 parent 90ca716 commit 29e861b

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_nam
34963496
ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->properties_info, prop) {
34973497
if (prop->ce == disabled_class) {
34983498
zend_string_release(prop->name);
3499-
zend_type_release(prop->type, /* persistent */ 1);
3499+
zend_type_release_internal(prop->type);
35003500
free(prop);
35013501
}
35023502
} ZEND_HASH_FOREACH_END();

Zend/zend_compile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,14 @@ ZEND_API void zend_destroy_static_vars(zend_op_array *op_array);
862862
ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle);
863863
ZEND_API void zend_cleanup_mutable_class_data(zend_class_entry *ce);
864864
ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce);
865+
/**
866+
* Used to release userland types.
867+
*/
865868
ZEND_API void zend_type_release(zend_type type, bool persistent);
869+
/**
870+
* Used to release types associated with internal functions or classes.
871+
*/
872+
ZEND_API void zend_type_release_internal(zend_type type);
866873
ZEND_API zend_string *zend_create_member_string(zend_string *class_name, zend_string *member_name);
867874

868875

Zend/zend_opcode.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ ZEND_API void zend_type_release(zend_type type, bool persistent) {
118118
zend_string_release(ZEND_TYPE_NAME(*sublist_type));
119119
}
120120
} ZEND_TYPE_LIST_FOREACH_END();
121-
if (!ZEND_TYPE_USES_ARENA(*list_type) && persistent) {
122-
free(ZEND_TYPE_LIST(*list_type));
123-
}
124121
} else if (ZEND_TYPE_HAS_NAME(*list_type)) {
125122
zend_string_release(ZEND_TYPE_NAME(*list_type));
126123
}
@@ -133,6 +130,28 @@ ZEND_API void zend_type_release(zend_type type, bool persistent) {
133130
}
134131
}
135132

133+
ZEND_API void zend_type_release_internal(zend_type type) {
134+
ZEND_ASSERT(!ZEND_TYPE_USES_ARENA(type));
135+
if (ZEND_TYPE_HAS_LIST(type)) {
136+
zend_type *list_type, *sublist_type;
137+
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(type), list_type) {
138+
if (ZEND_TYPE_HAS_LIST(*list_type)) {
139+
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*list_type), sublist_type) {
140+
if (ZEND_TYPE_HAS_NAME(*sublist_type)) {
141+
zend_string_release(ZEND_TYPE_NAME(*sublist_type));
142+
}
143+
} ZEND_TYPE_LIST_FOREACH_END();
144+
free(ZEND_TYPE_LIST(*list_type));
145+
} else if (ZEND_TYPE_HAS_NAME(*list_type)) {
146+
zend_string_release(ZEND_TYPE_NAME(*list_type));
147+
}
148+
} ZEND_TYPE_LIST_FOREACH_END();
149+
free(ZEND_TYPE_LIST(type));
150+
} else if (ZEND_TYPE_HAS_NAME(type)) {
151+
zend_string_release(ZEND_TYPE_NAME(type));
152+
}
153+
}
154+
136155
void zend_free_internal_arg_info(zend_internal_function *function) {
137156
if ((function->fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) &&
138157
function->arg_info) {
@@ -145,7 +164,7 @@ void zend_free_internal_arg_info(zend_internal_function *function) {
145164
num_args++;
146165
}
147166
for (i = 0 ; i < num_args; i++) {
148-
zend_type_release(arg_info[i].type, /* persistent */ 1);
167+
zend_type_release_internal(arg_info[i].type);
149168
}
150169
free(arg_info);
151170
}
@@ -457,7 +476,7 @@ ZEND_API void destroy_zend_class(zval *zv)
457476
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop_info) {
458477
if (prop_info->ce == ce) {
459478
zend_string_release(prop_info->name);
460-
zend_type_release(prop_info->type, /* persistent */ 1);
479+
zend_type_release_internal(prop_info->type);
461480
free(prop_info);
462481
}
463482
} ZEND_HASH_FOREACH_END();
@@ -492,6 +511,7 @@ ZEND_API void destroy_zend_class(zval *zv)
492511
} else {
493512
zval_internal_ptr_dtor(&c->value);
494513
}
514+
zend_type_release_internal(c->type);
495515
if (c->doc_comment) {
496516
zend_string_release_ex(c->doc_comment, 1);
497517
}

0 commit comments

Comments
 (0)