@@ -553,13 +553,15 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec
553
553
if (Z_TYPE_P (data ) == IS_INDIRECT ) {
554
554
data = Z_INDIRECT_P (data );
555
555
if (Z_TYPE_P (data ) != IS_UNDEF ) {
556
- zval_ptr_dtor (data );
556
+ zval garbage ;
557
+ ZVAL_COPY_VALUE (& garbage , data );
557
558
ZVAL_UNDEF (data );
558
559
HT_FLAGS (ht ) |= HASH_FLAG_HAS_EMPTY_IND ;
559
560
zend_hash_move_forward_ex (ht , spl_array_get_pos_ptr (ht , intern ));
560
561
if (spl_array_is_object (intern )) {
561
562
spl_array_skip_protected (intern , ht );
562
563
}
564
+ zval_ptr_dtor (& garbage );
563
565
}
564
566
} else {
565
567
zend_hash_del (ht , key .key );
@@ -931,8 +933,10 @@ static zend_result spl_array_skip_protected(spl_array_object *intern, HashTable
931
933
static void spl_array_set_array (zval * object , spl_array_object * intern , zval * array , zend_long ar_flags , bool just_array ) {
932
934
/* Handled by ZPP prior to this, or for __unserialize() before passing to here */
933
935
ZEND_ASSERT (Z_TYPE_P (array ) == IS_ARRAY || Z_TYPE_P (array ) == IS_OBJECT );
936
+ zval garbage ;
937
+ ZVAL_UNDEF (& garbage );
934
938
if (Z_TYPE_P (array ) == IS_ARRAY ) {
935
- zval_ptr_dtor ( & intern -> array );
939
+ ZVAL_COPY_VALUE ( & garbage , & intern -> array );
936
940
if (Z_REFCOUNT_P (array ) == 1 ) {
937
941
ZVAL_COPY (& intern -> array , array );
938
942
} else {
@@ -950,7 +954,7 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
950
954
}
951
955
} else {
952
956
if (Z_OBJ_HT_P (array ) == & spl_handler_ArrayObject ) {
953
- zval_ptr_dtor ( & intern -> array );
957
+ ZVAL_COPY_VALUE ( & garbage , & intern -> array );
954
958
if (just_array ) {
955
959
spl_array_object * other = Z_SPLARRAY_P (array );
956
960
ar_flags = other -> ar_flags & ~SPL_ARRAY_INT_MASK ;
@@ -968,15 +972,17 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
968
972
zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 ,
969
973
"Overloaded object of type %s is not compatible with %s" ,
970
974
ZSTR_VAL (Z_OBJCE_P (array )-> name ), ZSTR_VAL (intern -> std .ce -> name ));
975
+ ZEND_ASSERT (Z_TYPE (garbage ) == IS_UNDEF );
971
976
return ;
972
977
}
973
978
if (UNEXPECTED (Z_OBJCE_P (array )-> ce_flags & ZEND_ACC_ENUM )) {
974
979
zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 ,
975
980
"Enums are not compatible with %s" ,
976
981
ZSTR_VAL (intern -> std .ce -> name ));
982
+ ZEND_ASSERT (Z_TYPE (garbage ) == IS_UNDEF );
977
983
return ;
978
984
}
979
- zval_ptr_dtor ( & intern -> array );
985
+ ZVAL_COPY_VALUE ( & garbage , & intern -> array );
980
986
ZVAL_COPY (& intern -> array , array );
981
987
}
982
988
}
@@ -987,6 +993,8 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
987
993
zend_hash_iterator_del (intern -> ht_iter );
988
994
intern -> ht_iter = (uint32_t )-1 ;
989
995
}
996
+
997
+ zval_ptr_dtor (& garbage );
990
998
}
991
999
/* }}} */
992
1000
0 commit comments