Skip to content

Commit dc8705c

Browse files
committed
Fixed issue #135 (segfault in interned strings if initial memory is too low)
1 parent f7eff9c commit dc8705c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ PHP NEWS
2929
. Fixed bug #65665 (Exception not properly caught when opcache enabled).
3030
(Laruence)
3131
. Fixed bug #65510 (5.5.2 crashes in _get_zval_ptr_ptr_var). (Dmitry)
32+
. Fixed issue #135 (segfault in interned strings if initial memory is too
33+
low). (Julien)
3234

3335
- SPL:
3436
. Fix bug #64782 (SplFileObject constructor make $context optional / give it

ext/opcache/ZendAccelerator.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,14 +2407,14 @@ static inline int accel_find_sapi(TSRMLS_D)
24072407
return FAILURE;
24082408
}
24092409

2410-
static void zend_accel_init_shm(TSRMLS_D)
2410+
static int zend_accel_init_shm(TSRMLS_D)
24112411
{
24122412
zend_shared_alloc_lock(TSRMLS_C);
24132413

24142414
accel_shared_globals = zend_shared_alloc(sizeof(zend_accel_shared_globals));
24152415
if (!accel_shared_globals) {
24162416
zend_accel_error(ACCEL_LOG_FATAL, "Insufficient shared memory!");
2417-
return;
2417+
return FAILURE;
24182418
}
24192419
ZSMMG(app_shared_globals) = accel_shared_globals;
24202420

@@ -2429,7 +2429,8 @@ static void zend_accel_init_shm(TSRMLS_D)
24292429
ZCSG(interned_strings).arBuckets = zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket *));
24302430
ZCSG(interned_strings_start) = zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 1024));
24312431
if (!ZCSG(interned_strings).arBuckets || !ZCSG(interned_strings_start)) {
2432-
zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
2432+
zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
2433+
return FAILURE;
24332434
}
24342435
ZCSG(interned_strings_end) = ZCSG(interned_strings_start) + (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
24352436
ZCSG(interned_strings_top) = ZCSG(interned_strings_start);
@@ -2468,6 +2469,8 @@ static void zend_accel_init_shm(TSRMLS_D)
24682469
ZCSG(restart_in_progress) = 0;
24692470

24702471
zend_shared_alloc_unlock(TSRMLS_C);
2472+
2473+
return SUCCESS;
24712474
}
24722475

24732476
static void accel_globals_ctor(zend_accel_globals *accel_globals TSRMLS_DC)
@@ -2525,7 +2528,10 @@ static int accel_startup(zend_extension *extension)
25252528
/********************************************/
25262529
switch (zend_shared_alloc_startup(ZCG(accel_directives).memory_consumption)) {
25272530
case ALLOC_SUCCESS:
2528-
zend_accel_init_shm(TSRMLS_C);
2531+
if (zend_accel_init_shm(TSRMLS_C) == FAILURE) {
2532+
accel_startup_ok = 0;
2533+
return FAILURE;
2534+
}
25292535
break;
25302536
case ALLOC_FAILURE:
25312537
accel_startup_ok = 0;

0 commit comments

Comments
 (0)