@@ -157,15 +157,17 @@ static spl_SplObjectStorageElement *spl_object_storage_attach_handle(spl_SplObje
157
157
ZEND_ASSERT (intern -> fptrs == NULL || !intern -> fptrs -> override_write_dimension );
158
158
159
159
if (Z_TYPE_P (entry_zv ) != IS_NULL ) {
160
+ zval zv_inf ;
160
161
ZEND_ASSERT (Z_TYPE_P (entry_zv ) == IS_PTR );
161
162
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 );
164
164
if (inf ) {
165
165
ZVAL_COPY (& pelement -> inf , inf );
166
166
} else {
167
167
ZVAL_NULL (& pelement -> inf );
168
168
}
169
+ /* Call the old value's destructor last, in case it moves the entry */
170
+ zval_ptr_dtor (& zv_inf );
169
171
return pelement ;
170
172
}
171
173
@@ -190,14 +192,16 @@ spl_SplObjectStorageElement *spl_object_storage_attach(spl_SplObjectStorage *int
190
192
pelement = spl_object_storage_get (intern , & key );
191
193
192
194
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 );
195
197
if (inf ) {
196
198
ZVAL_COPY (& pelement -> inf , inf );
197
199
} else {
198
200
ZVAL_NULL (& pelement -> inf );
199
201
}
200
202
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 );
201
205
return pelement ;
202
206
}
203
207
0 commit comments