Skip to content

Commit 52fec69

Browse files
committed
Do not null out obj->properties when resetting object
Engine expects the properties ht to be separated, assigned a new ht, or resized, but never to be nulled.
1 parent 4d7fcea commit 52fec69

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Zend/zend_lazy_objects.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ ZEND_API bool zend_class_can_be_lazy(zend_class_entry *ce)
199199
return true;
200200
}
201201

202+
static int zlo_hash_remove_dyn_props_func(zval *pDest)
203+
{
204+
if (Z_TYPE_P(pDest) == IS_INDIRECT) {
205+
return ZEND_HASH_APPLY_STOP;
206+
}
207+
208+
return ZEND_HASH_APPLY_REMOVE;
209+
}
210+
202211
/* Make object 'obj' lazy. If 'obj' is NULL, create a lazy instance of
203212
* class 'reflection_ce' */
204213
ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,
@@ -278,9 +287,17 @@ ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,
278287

279288
GC_DEL_FLAGS(obj, IS_OBJ_DESTRUCTOR_CALLED);
280289

281-
/* unset() dynamic properties */
282-
zend_object_dtor_dynamic_properties(obj);
283-
obj->properties = NULL;
290+
/* unset() dynamic properties. Do not NULL out obj->properties, as this
291+
* would be unexpected. */
292+
if (obj->properties) {
293+
if (UNEXPECTED(GC_REFCOUNT(obj->properties) > 1)) {
294+
if (EXPECTED(!(GC_FLAGS(obj->properties) & IS_ARRAY_IMMUTABLE))) {
295+
GC_DELREF(obj->properties);
296+
}
297+
obj->properties = zend_array_dup(obj->properties);
298+
}
299+
zend_hash_reverse_apply(obj->properties, zlo_hash_remove_dyn_props_func);
300+
}
284301

285302
/* unset() declared properties */
286303
for (int i = 0; i < reflection_ce->default_properties_count; i++) {

0 commit comments

Comments
 (0)