@@ -860,9 +860,6 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
860
860
return ;
861
861
862
862
case IS_OBJECT : {
863
- zval retval ;
864
- zval fname ;
865
- int res ;
866
863
zend_class_entry * ce = Z_OBJCE_P (struc );
867
864
868
865
if (ce -> serialize != NULL ) {
@@ -891,32 +888,39 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
891
888
}
892
889
893
890
if (ce != PHP_IC_ENTRY && zend_hash_str_exists (& ce -> function_table , "__sleep" , sizeof ("__sleep" )- 1 )) {
891
+ zval fname , tmp , retval ;
892
+ int res ;
893
+
894
+ ZVAL_COPY (& tmp , struc );
894
895
ZVAL_STRINGL (& fname , "__sleep" , sizeof ("__sleep" ) - 1 );
895
896
BG (serialize_lock )++ ;
896
- res = call_user_function_ex (CG (function_table ), struc , & fname , & retval , 0 , 0 , 1 , NULL );
897
+ res = call_user_function_ex (CG (function_table ), & tmp , & fname , & retval , 0 , 0 , 1 , NULL );
897
898
BG (serialize_lock )-- ;
898
899
zval_dtor (& fname );
899
900
900
901
if (EG (exception )) {
901
902
zval_ptr_dtor (& retval );
903
+ zval_ptr_dtor (& tmp );
902
904
return ;
903
905
}
904
906
905
907
if (res == SUCCESS ) {
906
908
if (Z_TYPE (retval ) != IS_UNDEF ) {
907
909
if (HASH_OF (& retval )) {
908
- php_var_serialize_class (buf , struc , & retval , var_hash );
910
+ php_var_serialize_class (buf , & tmp , & retval , var_hash );
909
911
} else {
910
912
php_error_docref (NULL , E_NOTICE , "__sleep should return an array only containing the names of instance-variables to serialize" );
911
913
/* we should still add element even if it's not OK,
912
914
* since we already wrote the length of the array before */
913
915
smart_str_appendl (buf ,"N;" , 2 );
914
916
}
915
- zval_ptr_dtor (& retval );
916
917
}
918
+ zval_ptr_dtor (& retval );
919
+ zval_ptr_dtor (& tmp );
917
920
return ;
918
921
}
919
922
zval_ptr_dtor (& retval );
923
+ zval_ptr_dtor (& tmp );
920
924
}
921
925
922
926
/* fall-through */
0 commit comments