@@ -253,15 +253,18 @@ static void *zend_file_cache_serialize_interned(zend_string *str,
253
253
len = ZEND_MM_ALIGNED_SIZE (_ZSTR_STRUCT_SIZE (ZSTR_LEN (str )));
254
254
ret = (void * )(info -> str_size | Z_UL (1 ));
255
255
zend_shared_alloc_register_xlat_entry (str , ret );
256
- if (info -> str_size + len > ZSTR_LEN ((zend_string * )ZCG (mem ))) {
256
+
257
+ zend_string * s = (zend_string * )ZCG (mem );
258
+ if (info -> str_size + len > ZSTR_LEN (s )) {
257
259
size_t new_len = info -> str_size + len ;
258
- ZCG ( mem ) = ( void * ) zend_string_realloc (
259
- ( zend_string * ) ZCG ( mem ) ,
260
+ s = zend_string_realloc (
261
+ s ,
260
262
((_ZSTR_HEADER_SIZE + 1 + new_len + 4095 ) & ~0xfff ) - (_ZSTR_HEADER_SIZE + 1 ),
261
263
0 );
264
+ ZCG (mem ) = (void * )s ;
262
265
}
263
266
264
- zend_string * new_str = (zend_string * ) (ZSTR_VAL (( zend_string * ) ZCG ( mem ) ) + info -> str_size );
267
+ zend_string * new_str = (zend_string * ) (ZSTR_VAL (s ) + info -> str_size );
265
268
memcpy (new_str , str , len );
266
269
GC_ADD_FLAGS (new_str , IS_STR_INTERNED );
267
270
GC_DEL_FLAGS (new_str , IS_STR_PERMANENT |IS_STR_CLASS_NAME_MAP_PTR );
@@ -1063,8 +1066,10 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1063
1066
}
1064
1067
zend_shared_alloc_destroy_xlat_table ();
1065
1068
1069
+ zend_string * const s = (zend_string * )ZCG (mem );
1070
+
1066
1071
info .checksum = zend_adler32 (ADLER32_INIT , buf , script -> size );
1067
- info .checksum = zend_adler32 (info .checksum , (unsigned char * )ZSTR_VAL (( zend_string * ) ZCG ( mem ) ), info .str_size );
1072
+ info .checksum = zend_adler32 (info .checksum , (unsigned char * )ZSTR_VAL (s ), info .str_size );
1068
1073
1069
1074
#if __has_feature (memory_sanitizer )
1070
1075
/* The buffer may contain uninitialized regions. However, the uninitialized parts will not be
@@ -1078,12 +1083,12 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1078
1083
const struct iovec vec [] = {
1079
1084
{ .iov_base = (void * )& info , .iov_len = sizeof (info ) },
1080
1085
{ .iov_base = buf , .iov_len = script -> size },
1081
- { .iov_base = ZSTR_VAL (( zend_string * ) ZCG ( mem ) ), .iov_len = info .str_size },
1086
+ { .iov_base = ZSTR_VAL (s ), .iov_len = info .str_size },
1082
1087
};
1083
1088
1084
1089
if (writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ])) != (ssize_t )(sizeof (info ) + script -> size + info .str_size )) {
1085
1090
zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s'\n" , filename );
1086
- zend_string_release_ex (( zend_string * ) ZCG ( mem ) , 0 );
1091
+ zend_string_release_ex (s , 0 );
1087
1092
close (fd );
1088
1093
efree (mem );
1089
1094
zend_file_cache_unlink (filename );
@@ -1094,10 +1099,10 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1094
1099
if (ZEND_LONG_MAX < (zend_long )(sizeof (info ) + script -> size + info .str_size ) ||
1095
1100
write (fd , & info , sizeof (info )) != sizeof (info ) ||
1096
1101
write (fd , buf , script -> size ) != script -> size ||
1097
- write (fd , (( zend_string * ) ZCG ( mem )) -> val , info .str_size ) != info .str_size
1102
+ write (fd , s -> val , info .str_size ) != info .str_size
1098
1103
) {
1099
1104
zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s'\n" , filename );
1100
- zend_string_release_ex (( zend_string * ) ZCG ( mem ) , 0 );
1105
+ zend_string_release_ex (s , 0 );
1101
1106
close (fd );
1102
1107
efree (mem );
1103
1108
zend_file_cache_unlink (filename );
@@ -1106,7 +1111,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1106
1111
}
1107
1112
#endif
1108
1113
1109
- zend_string_release_ex (( zend_string * ) ZCG ( mem ) , 0 );
1114
+ zend_string_release_ex (s , 0 );
1110
1115
efree (mem );
1111
1116
if (zend_file_cache_flock (fd , LOCK_UN ) != 0 ) {
1112
1117
zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot unlock file '%s'\n" , filename );
0 commit comments