diff options
author | Julien Pauli <jpauli@php.net> | 2016-09-23 13:53:22 +0200 |
---|---|---|
committer | Julien Pauli <jpauli@php.net> | 2016-09-23 13:53:22 +0200 |
commit | fbf87a8082392ced4385b1a128cfe1caf7adf363 (patch) | |
tree | f2e7ca6c3e64016cc7920ec8815237ed79786008 /sapi/fpm | |
parent | deda0587512724d61eab33317359e7c98715f0c6 (diff) | |
parent | a22175b06f22965e0d79e2b5bb6c734950adfc5d (diff) | |
download | php-git-fbf87a8082392ced4385b1a128cfe1caf7adf363.tar.gz |
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
Formatting. Fix possible memory corruption in FPM SHM management
fix every work call mmap
Diffstat (limited to 'sapi/fpm')
-rw-r--r-- | sapi/fpm/fpm/fpm_scoreboard.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/sapi/fpm/fpm/fpm_scoreboard.c b/sapi/fpm/fpm/fpm_scoreboard.c index 209f8d23dc..5693ce4e49 100644 --- a/sapi/fpm/fpm/fpm_scoreboard.c +++ b/sapi/fpm/fpm/fpm_scoreboard.c @@ -25,7 +25,7 @@ static float fpm_scoreboard_tick; int fpm_scoreboard_init_main() /* {{{ */ { struct fpm_worker_pool_s *wp; - int i; + unsigned int i; #ifdef HAVE_TIMES #if (defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)) @@ -42,6 +42,9 @@ int fpm_scoreboard_init_main() /* {{{ */ for (wp = fpm_worker_all_pools; wp; wp = wp->next) { + size_t scoreboard_size, scoreboard_nprocs_size; + void *shm_mem; + if (wp->config->pm_max_children < 1) { zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because max_client is not set", wp->config->name); return -1; @@ -52,19 +55,22 @@ int fpm_scoreboard_init_main() /* {{{ */ return -1; } - wp->scoreboard = fpm_shm_alloc(sizeof(struct fpm_scoreboard_s) + (wp->config->pm_max_children - 1) * sizeof(struct fpm_scoreboard_proc_s *)); - if (!wp->scoreboard) { + scoreboard_size = sizeof(struct fpm_scoreboard_s) + (wp->config->pm_max_children) * sizeof(struct fpm_scoreboard_proc_s *); + scoreboard_nprocs_size = sizeof(struct fpm_scoreboard_proc_s) * wp->config->pm_max_children; + shm_mem = fpm_shm_alloc(scoreboard_size + scoreboard_nprocs_size); + + if (!shm_mem) { return -1; } + wp->scoreboard = shm_mem; wp->scoreboard->nprocs = wp->config->pm_max_children; - for (i = 0; i < wp->scoreboard->nprocs; i++) { - wp->scoreboard->procs[i] = fpm_shm_alloc(sizeof(struct fpm_scoreboard_proc_s)); - if (!wp->scoreboard->procs[i]) { - return -1; - } + shm_mem += scoreboard_size; + + for (i = 0; i < wp->scoreboard->nprocs; i++, shm_mem += sizeof(struct fpm_scoreboard_proc_s)) { + wp->scoreboard->procs[i] = shm_mem; } - wp->scoreboard->pm = wp->config->pm; + wp->scoreboard->pm = wp->config->pm; wp->scoreboard->start_epoch = time(NULL); strlcpy(wp->scoreboard->pool, wp->config->name, sizeof(wp->scoreboard->pool)); } @@ -232,20 +238,17 @@ void fpm_scoreboard_proc_release(struct fpm_scoreboard_proc_s *proc) /* {{{ */ void fpm_scoreboard_free(struct fpm_scoreboard_s *scoreboard) /* {{{ */ { - int i; + size_t scoreboard_size, scoreboard_nprocs_size; if (!scoreboard) { zlog(ZLOG_ERROR, "**scoreboard is NULL"); return; } - for (i = 0; i < scoreboard->nprocs; i++) { - if (!scoreboard->procs[i]) { - continue; - } - fpm_shm_free(scoreboard->procs[i], sizeof(struct fpm_scoreboard_proc_s)); - } - fpm_shm_free(scoreboard, sizeof(struct fpm_scoreboard_s)); + scoreboard_size = sizeof(struct fpm_scoreboard_s) + (scoreboard->nprocs) * sizeof(struct fpm_scoreboard_proc_s *); + scoreboard_nprocs_size = sizeof(struct fpm_scoreboard_proc_s) * scoreboard->nprocs; + + fpm_shm_free(scoreboard, scoreboard_size + scoreboard_nprocs_size); } /* }}} */ |