Skip to content

Commit d927b74

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix static prop cleanup for dl'ed internal classes
2 parents 065d00f + 3d55386 commit d927b74

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

Zend/tests/bug78335_2.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Bug #78335: Static properties containing cycles report as leak (internal class variant)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("zend-test")) die("skip requires zend-test"); ?>
35
--FILE--
46
<?php
57

Zend/zend_opcode.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,42 @@ ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce)
152152
zval *static_members = CE_STATIC_MEMBERS(ce);
153153
zval *p = static_members;
154154
zval *end = p + ce->default_static_members_count;
155-
156-
ZEND_MAP_PTR_SET(ce->static_members_table, NULL);
157-
while (p != end) {
158-
if (UNEXPECTED(Z_ISREF_P(p))) {
159-
zend_property_info *prop_info;
160-
ZEND_REF_FOREACH_TYPE_SOURCES(Z_REF_P(p), prop_info) {
161-
if (prop_info->ce == ce && p - static_members == prop_info->offset) {
162-
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(p), prop_info);
163-
break; /* stop iteration here, the array might be realloc()'ed */
164-
}
165-
} ZEND_REF_FOREACH_TYPE_SOURCES_END();
155+
if (UNEXPECTED(ZEND_MAP_PTR(ce->static_members_table) == &ce->default_static_members_table)) {
156+
/* Special case: If this is a static property on a dl'ed internal class, then the
157+
* static property table and the default property table are the same. In this case we
158+
* destroy the values here, but leave behind valid UNDEF zvals and don't free the
159+
* table itself. */
160+
while (p != end) {
161+
if (UNEXPECTED(Z_ISREF_P(p))) {
162+
zend_property_info *prop_info;
163+
ZEND_REF_FOREACH_TYPE_SOURCES(Z_REF_P(p), prop_info) {
164+
if (prop_info->ce == ce && p - static_members == prop_info->offset) {
165+
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(p), prop_info);
166+
break; /* stop iteration here, the array might be realloc()'ed */
167+
}
168+
} ZEND_REF_FOREACH_TYPE_SOURCES_END();
169+
}
170+
i_zval_ptr_dtor(p);
171+
ZVAL_UNDEF(p);
172+
p++;
173+
}
174+
} else {
175+
ZEND_MAP_PTR_SET(ce->static_members_table, NULL);
176+
while (p != end) {
177+
if (UNEXPECTED(Z_ISREF_P(p))) {
178+
zend_property_info *prop_info;
179+
ZEND_REF_FOREACH_TYPE_SOURCES(Z_REF_P(p), prop_info) {
180+
if (prop_info->ce == ce && p - static_members == prop_info->offset) {
181+
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(p), prop_info);
182+
break; /* stop iteration here, the array might be realloc()'ed */
183+
}
184+
} ZEND_REF_FOREACH_TYPE_SOURCES_END();
185+
}
186+
i_zval_ptr_dtor(p);
187+
p++;
166188
}
167-
i_zval_ptr_dtor(p);
168-
p++;
189+
efree(static_members);
169190
}
170-
efree(static_members);
171191
}
172192
}
173193

0 commit comments

Comments
 (0)