Skip to content

Commit c16f954

Browse files
committed
Clear alocated memory blocks, only if this is really necessary.
1 parent 1dfb63f commit c16f954

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,9 +1361,15 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
13611361
#ifdef __SSE2__
13621362
/* Align to 64-byte boundary */
13631363
ZCG(mem) = zend_shared_alloc(memory_used + 64);
1364-
ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 63L) & ~63L);
1364+
if (ZCG(mem)) {
1365+
memset(ZCG(mem), 0, memory_used + 64);
1366+
ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 63L) & ~63L);
1367+
}
13651368
#else
13661369
ZCG(mem) = zend_shared_alloc(memory_used);
1370+
if (ZCG(mem)) {
1371+
memset(ZCG(mem), 0, memory_used);
1372+
}
13671373
#endif
13681374
if (!ZCG(mem)) {
13691375
zend_shared_alloc_destroy_xlat_table();
@@ -2542,6 +2548,7 @@ static int zend_accel_init_shm(void)
25422548
zend_shared_alloc_unlock();
25432549
return FAILURE;
25442550
}
2551+
memset(accel_shared_globals, 0, sizeof(zend_accel_shared_globals));
25452552
ZSMMG(app_shared_globals) = accel_shared_globals;
25462553

25472554
zend_accel_hash_init(&ZCSG(hash), ZCG(accel_directives).max_accelerated_files);

ext/opcache/zend_shared_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ int zend_shared_alloc_startup(size_t requested_size)
230230
zend_accel_error(ACCEL_LOG_FATAL, "Insufficient shared memory!");
231231
return ALLOC_FAILURE;;
232232
}
233+
memset(p_tmp_shared_globals, 0, sizeof(zend_smm_shared_globals));
233234

234235
tmp_shared_segments = zend_shared_alloc(shared_segments_array_size + ZSMMG(shared_segments_count) * sizeof(void *));
235236
if (!tmp_shared_segments) {
@@ -325,7 +326,6 @@ void *zend_shared_alloc(size_t size)
325326

326327
ZSMMG(shared_segments)[i]->pos += block_size;
327328
ZSMMG(shared_free) -= block_size;
328-
memset(retval, 0, block_size);
329329
ZEND_ASSERT(((zend_uintptr_t)retval & 0x7) == 0); /* should be 8 byte aligned */
330330
return retval;
331331
}

0 commit comments

Comments
 (0)