Skip to content

Commit c18a585

Browse files
committed
fix memory leak
1 parent 9896c3b commit c18a585

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Zend/zend_API.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,9 @@ static HashTable *interned_type_tree = NULL;
29032903
ZEND_API void zend_type_free_interned_trees(void) {
29042904
zend_type_node *tree = NULL;
29052905
ZEND_HASH_FOREACH_PTR(interned_type_tree, tree) {
2906+
if (tree->kind != ZEND_TYPE_SIMPLE) {
2907+
pefree(tree->compound.types, 1);
2908+
}
29062909
pefree(tree, 1);
29072910
} ZEND_HASH_FOREACH_END();
29082911
pefree(interned_type_tree, 1);
@@ -3055,6 +3058,9 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
30553058

30563059
if ((existing = zend_hash_index_find_ptr(interned_type_tree, hash))) {
30573060
if (zend_type_node_equals(existing, node)) {
3061+
if (node->kind != ZEND_TYPE_SIMPLE) {
3062+
pefree(node->compound.types, 1);
3063+
}
30583064
pefree(node, 1);
30593065
return existing; // reuse interned node
30603066
}
@@ -3085,15 +3091,17 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(const zend_type type) {
30853091

30863092
zend_type *subtype;
30873093

3094+
children = pemalloc(list->num_types * sizeof(zend_type_node *), 1);
3095+
30883096
ZEND_TYPE_LIST_FOREACH(list, subtype) {
30893097
zend_type_node *child = zend_type_to_interned_tree(*subtype);
30903098

30913099
if (child->kind == kind) {
30923100
for (uint32_t i = 0; i < child->compound.num_types; i++) {
3093-
ADD_TO_TYPE_TREE(children, num_children, child->compound.types[i]);
3101+
children[num_children++] = child->compound.types[i];
30943102
}
30953103
} else {
3096-
ADD_TO_TYPE_TREE(children, num_children, child);
3104+
children[num_children++] = child;
30973105
}
30983106
} ZEND_TYPE_LIST_FOREACH_END();
30993107

Zend/zend_types.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,6 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
814814
#define IS_TYPE_REFCOUNTED (1<<0)
815815
#define IS_TYPE_COLLECTABLE (1<<1)
816816

817-
#define ADD_TO_TYPE_TREE(list, count, value) \
818-
do { \
819-
list = erealloc(list, sizeof(zend_type) * (count + 1)); \
820-
list[count++] = value; \
821-
} while (0)
822-
823-
824817
#if 1
825818
/* This optimized version assumes that we have a single "type_flag" */
826819
/* IS_TYPE_COLLECTABLE may be used only with IS_TYPE_REFCOUNTED */

0 commit comments

Comments
 (0)