Skip to content

Commit 784e1a5

Browse files
committed
Call destructor after overriding old SplObjectStorage entry
1 parent 989f0e9 commit 784e1a5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ext/spl/spl_observer.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ static spl_SplObjectStorageElement *spl_object_storage_attach_handle(spl_SplObje
157157
ZEND_ASSERT(intern->fptrs == NULL || !intern->fptrs->override_write_dimension);
158158

159159
if (Z_TYPE_P(entry_zv) != IS_NULL) {
160+
zval zv_inf;
160161
ZEND_ASSERT(Z_TYPE_P(entry_zv) == IS_PTR);
161162
pelement = Z_PTR_P(entry_zv);
162-
/* FIXME unsafe if destructor of inf moves/removes this entry */
163-
zval_ptr_dtor(&pelement->inf);
163+
ZVAL_COPY_VALUE(&zv_inf, &pelement->inf);
164164
if (inf) {
165165
ZVAL_COPY(&pelement->inf, inf);
166166
} else {
167167
ZVAL_NULL(&pelement->inf);
168168
}
169+
/* Call the old value's destructor last, in case it moves the entry */
170+
zval_ptr_dtor(&zv_inf);
169171
return pelement;
170172
}
171173

@@ -190,14 +192,16 @@ spl_SplObjectStorageElement *spl_object_storage_attach(spl_SplObjectStorage *int
190192
pelement = spl_object_storage_get(intern, &key);
191193

192194
if (pelement) {
193-
/* FIXME unsafe if destructor of inf moves/removes this entry */
194-
zval_ptr_dtor(&pelement->inf);
195+
zval zv_inf;
196+
ZVAL_COPY_VALUE(&zv_inf, &pelement->inf);
195197
if (inf) {
196198
ZVAL_COPY(&pelement->inf, inf);
197199
} else {
198200
ZVAL_NULL(&pelement->inf);
199201
}
200202
spl_object_storage_free_hash(intern, &key);
203+
/* Call the old value's destructor last, in case it moves the entry */
204+
zval_ptr_dtor(&pelement->inf);
201205
return pelement;
202206
}
203207

0 commit comments

Comments
 (0)