Skip to content

Commit 0fbbd26

Browse files
committed
move some stuff around and clean up memory on shutdown
1 parent 429bb82 commit 0fbbd26

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

Zend/zend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ void zend_shutdown(void) /* {{{ */
11951195
free(GLOBAL_CONSTANTS_TABLE);
11961196
zend_shutdown_strtod();
11971197
zend_attributes_shutdown();
1198+
zend_type_free_interned_trees();
11981199

11991200
#ifdef ZTS
12001201
GLOBAL_FUNCTION_TABLE = NULL;

Zend/zend_API.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,12 +2900,13 @@ ZEND_END_ARG_INFO()
29002900

29012901
static HashTable *interned_type_tree = NULL;
29022902

2903-
// todo: move to zend_types.h
2904-
#define ADD_TO_TREE(list, count, value) \
2905-
do { \
2906-
list = erealloc(list, sizeof(zend_type) * (count + 1)); \
2907-
list[count++] = value; \
2908-
} while (0)
2903+
ZEND_API void zend_type_free_interned_trees(void) {
2904+
zend_type_node *tree = NULL;
2905+
ZEND_HASH_FOREACH_PTR(interned_type_tree, tree) {
2906+
pefree(tree, 1);
2907+
} ZEND_HASH_FOREACH_END();
2908+
pefree(interned_type_tree, 1);
2909+
}
29092910

29102911
static int compare_simple_types(const zend_type a, const zend_type b) {
29112912
const uint32_t a_mask = ZEND_TYPE_FULL_MASK(a);
@@ -3088,10 +3089,10 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(const zend_type type) {
30883089

30893090
if (child->kind == kind) {
30903091
for (uint32_t i = 0; child->compound.num_types; i++) {
3091-
ADD_TO_TREE(children, num_children, child->compound.types[i]);
3092+
ADD_TO_TYPE_TREE(children, num_children, child->compound.types[i]);
30923093
}
30933094
} else {
3094-
ADD_TO_TREE(children, num_children, child);
3095+
ADD_TO_TYPE_TREE(children, num_children, child);
30953096
}
30963097
} ZEND_TYPE_LIST_FOREACH_END();
30973098

Zend/zend_API.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type);
449449
ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_type);
450450

451451
ZEND_API zend_type_node *zend_type_to_interned_tree(zend_type type);
452+
ZEND_API void zend_type_free_interned_trees(void);
452453

453454
static zend_always_inline HashTable *zend_class_constants_table(zend_class_entry *ce) {
454455
if ((ce->ce_flags & ZEND_ACC_HAS_AST_CONSTANTS) && ZEND_MAP_PTR(ce->mutable_data)) {

Zend/zend_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,13 @@ 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+
817824
#if 1
818825
/* This optimized version assumes that we have a single "type_flag" */
819826
/* IS_TYPE_COLLECTABLE may be used only with IS_TYPE_REFCOUNTED */

0 commit comments

Comments
 (0)