Commit:    331540d20cb5b17964e6b2901c343df58bc8a0c9
Author:    Remi Collet <r...@php.net>         Thu, 2 May 2013 13:27:16 +0200
Parents:   d0c40220d1ba1d3d1e50ca122d1ec37e2d19c58a
Branches:  PHP-5.3 PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=331540d20cb5b17964e6b2901c343df58bc8a0c9

Log:
From code coverity scan
- fix some memory leak
- fix some resources leak (fd)
- create fpm_worker_pool_free (shared use)
- possible null dref (wp->user and wp->home can be null)

Changed paths:
  M  sapi/fpm/fpm/fpm_conf.c
  M  sapi/fpm/fpm/fpm_worker_pool.c
  M  sapi/fpm/fpm/fpm_worker_pool.h


Diff:
diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c
index d8a57c5..0a8a0e3 100644
--- a/sapi/fpm/fpm/fpm_conf.c
+++ b/sapi/fpm/fpm/fpm_conf.c
@@ -540,12 +540,17 @@ static char *fpm_conf_set_array(zval *key, zval *value, 
void **config, int conve
        kv->key = strdup(Z_STRVAL_P(key));
 
        if (!kv->key) {
+               free(kv);
                return "fpm_conf_set_array: strdup(key) failed";
        }
 
        if (convert_to_bool) {
                char *err = fpm_conf_set_boolean(value, &subconf, 0);
-               if (err) return err;
+               if (err) {
+                       free(kv->key);
+                       free(kv);
+                       return err;
+               }
                kv->value = strdup(b ? "1" : "0");
        } else {
                kv->value = strdup(Z_STRVAL_P(value));
@@ -556,6 +561,7 @@ static char *fpm_conf_set_array(zval *key, zval *value, 
void **config, int conve
 
        if (!kv->value) {
                free(kv->key);
+               free(kv);
                return "fpm_conf_set_array: strdup(value) failed";
        }
 
@@ -578,6 +584,7 @@ static void *fpm_worker_pool_config_alloc() /* {{{ */
        wp->config = malloc(sizeof(struct fpm_worker_pool_config_s));
 
        if (!wp->config) { 
+               fpm_worker_pool_free(wp);
                return 0;
        }
 
@@ -1107,6 +1114,7 @@ int fpm_conf_write_pid() /* {{{ */
 
                if (len != write(fd, buf, len)) {
                        zlog(ZLOG_SYSERROR, "Unable to write to the PID file.");
+                       close(fd);
                        return -1;
                }
                close(fd);
@@ -1460,6 +1468,7 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* 
{{{ */
 
        if (ini_recursion++ > 4) {
                zlog(ZLOG_ERROR, "failed to include more than 5 files 
recusively");
+               close(fd);
                return -1;
        }
 
diff --git a/sapi/fpm/fpm/fpm_worker_pool.c b/sapi/fpm/fpm/fpm_worker_pool.c
index 123f989..ebe1866 100644
--- a/sapi/fpm/fpm/fpm_worker_pool.c
+++ b/sapi/fpm/fpm/fpm_worker_pool.c
@@ -18,6 +18,21 @@
 
 struct fpm_worker_pool_s *fpm_worker_all_pools;
 
+void fpm_worker_pool_free(struct fpm_worker_pool_s *wp) /* {{{ */
+{
+       if (wp->config) {
+               free(wp->config);
+       }
+       if (wp->user) {
+               free(wp->user);
+       }
+       if (wp->home) {
+               free(wp->home);
+       }
+       free(wp);
+}
+/* }}} */
+
 static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */
 {
        struct fpm_worker_pool_s *wp, *wp_next;
@@ -29,10 +44,7 @@ static void fpm_worker_pool_cleanup(int which, void *arg) /* 
{{{ */
                if ((which & FPM_CLEANUP_CHILD) == 0 && fpm_globals.parent_pid 
== getpid()) {
                        fpm_scoreboard_free(wp->scoreboard);
                }
-               free(wp->config);
-               free(wp->user);
-               free(wp->home);
-               free(wp);
+               fpm_worker_pool_free(wp);
        }
        fpm_worker_all_pools = NULL;
 }
diff --git a/sapi/fpm/fpm/fpm_worker_pool.h b/sapi/fpm/fpm/fpm_worker_pool.h
index 6688e6d..05c993d 100644
--- a/sapi/fpm/fpm/fpm_worker_pool.h
+++ b/sapi/fpm/fpm/fpm_worker_pool.h
@@ -45,6 +45,7 @@ struct fpm_worker_pool_s {
 };
 
 struct fpm_worker_pool_s *fpm_worker_pool_alloc();
+void fpm_worker_pool_free(struct fpm_worker_pool_s *wp);
 int fpm_worker_pool_init_main();
 
 extern struct fpm_worker_pool_s *fpm_worker_all_pools;


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to