@@ -862,9 +862,6 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
862862 return ;
863863
864864 case IS_OBJECT : {
865- zval retval ;
866- zval fname ;
867- int res ;
868865 zend_class_entry * ce = Z_OBJCE_P (struc );
869866
870867 if (ce -> serialize != NULL ) {
@@ -893,32 +890,39 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
893890 }
894891
895892 if (ce != PHP_IC_ENTRY && zend_hash_str_exists (& ce -> function_table , "__sleep" , sizeof ("__sleep" )- 1 )) {
893+ zval fname , tmp , retval ;
894+ int res ;
895+
896+ ZVAL_COPY (& tmp , struc );
896897 ZVAL_STRINGL (& fname , "__sleep" , sizeof ("__sleep" ) - 1 );
897898 BG (serialize_lock )++ ;
898- res = call_user_function_ex (CG (function_table ), struc , & fname , & retval , 0 , 0 , 1 , NULL );
899+ res = call_user_function_ex (CG (function_table ), & tmp , & fname , & retval , 0 , 0 , 1 , NULL );
899900 BG (serialize_lock )-- ;
900901 zval_dtor (& fname );
901902
902903 if (EG (exception )) {
903904 zval_ptr_dtor (& retval );
905+ zval_ptr_dtor (& tmp );
904906 return ;
905907 }
906908
907909 if (res == SUCCESS ) {
908910 if (Z_TYPE (retval ) != IS_UNDEF ) {
909911 if (HASH_OF (& retval )) {
910- php_var_serialize_class (buf , struc , & retval , var_hash );
912+ php_var_serialize_class (buf , & tmp , & retval , var_hash );
911913 } else {
912914 php_error_docref (NULL , E_NOTICE , "__sleep should return an array only containing the names of instance-variables to serialize" );
913915 /* we should still add element even if it's not OK,
914916 * since we already wrote the length of the array before */
915917 smart_str_appendl (buf ,"N;" , 2 );
916918 }
917- zval_ptr_dtor (& retval );
918919 }
920+ zval_ptr_dtor (& retval );
921+ zval_ptr_dtor (& tmp );
919922 return ;
920923 }
921924 zval_ptr_dtor (& retval );
925+ zval_ptr_dtor (& tmp );
922926 }
923927
924928 /* fall-through */
0 commit comments