]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[CLEANUP] remove 65 useless NULL checks before free
authorWilly Tarreau <w@1wt.eu>
Sun, 3 Aug 2008 10:19:50 +0000 (12:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 3 Aug 2008 18:48:50 +0000 (20:48 +0200)
C specification clearly states that free(NULL) is a no-op.
So remove useless checks before calling free.

src/backend.c
src/cfgparse.c
src/ev_epoll.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c
src/ev_sepoll.c
src/haproxy.c
src/uri_auth.c

index 7fbc7206dad9dca187f89abce0933a49c8e1c4c4..f1346719f6eeec107b3b11499563a948ffa8cf9b 100644 (file)
@@ -2078,10 +2078,10 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy
                }
                curproxy->lbprm.algo &= ~BE_LB_ALGO;
                curproxy->lbprm.algo |= BE_LB_ALGO_PH;
-               if (curproxy->url_param_name)
-                       free(curproxy->url_param_name);
+
+               free(curproxy->url_param_name);
                curproxy->url_param_name = strdup(args[1]);
-               curproxy->url_param_len = strlen(args[1]);
+               curproxy->url_param_len  = strlen(args[1]);
                if (*args[2]) {
                        if (strcmp(args[2], "check_post")) {
                                snprintf(err, errlen, "'balance url_param' only accepts check_post modifier.");
index ea73f537559ee54ac021c7d976b27f909d42f44d..78783c0477f449d30e52e10e1a0c5ee4d74b9611 100644 (file)
@@ -715,17 +715,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                /* FIXME-20070101: we should do this too at the end of the
                 * config parsing to free all default values.
                 */
-               if (defproxy.check_req)     free(defproxy.check_req);
-               if (defproxy.cookie_name)   free(defproxy.cookie_name);
-               if (defproxy.url_param_name) free(defproxy.url_param_name);
-               if (defproxy.capture_name)  free(defproxy.capture_name);
-               if (defproxy.monitor_uri)   free(defproxy.monitor_uri);
-               if (defproxy.defbe.name)    free(defproxy.defbe.name);
+               free(defproxy.check_req);
+               free(defproxy.cookie_name);
+               free(defproxy.url_param_name);
+               free(defproxy.capture_name);
+               free(defproxy.monitor_uri);
+               free(defproxy.defbe.name);
 
-               for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
-                       if (defproxy.errmsg[rc].len)
-                               free(defproxy.errmsg[rc].str);
-               }
+               for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
+                       free(defproxy.errmsg[rc].str);
 
                /* we cannot free uri_auth because it might already be used */
                init_default_instance();
@@ -804,9 +802,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                        return -1;
                }
 
-               if (curproxy->monitor_uri != NULL)
-                       free(curproxy->monitor_uri);
-
+               free(curproxy->monitor_uri);
                curproxy->monitor_uri_len = strlen(args[1]);
                curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1);
                memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
@@ -875,26 +871,17 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
        }
        else if (!strcmp(args[0], "cookie")) {  /* cookie name */
                int cur_arg;
-               //        if (curproxy == &defproxy) {
-               //            Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
-               //            return -1;
-               //        }
 
                if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        return 0;
 
-               if (curproxy->cookie_name != NULL) {
-                       //            Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
-                       //                  file, linenum);
-                       //            return 0;
-                       free(curproxy->cookie_name);
-               }
-       
                if (*(args[1]) == 0) {
                        Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
                              file, linenum, args[0]);
                        return -1;
                }
+
+               free(curproxy->cookie_name);
                curproxy->cookie_name = strdup(args[1]);
                curproxy->cookie_len = strlen(curproxy->cookie_name);
        
@@ -963,27 +950,17 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                }
        }/* end else if (!strcmp(args[0], "cookie"))  */
        else if (!strcmp(args[0], "appsession")) {  /* cookie name */
-               //        if (curproxy == &defproxy) {
-               //            Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
-               //            return -1;
-               //        }
 
                if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        return 0;
 
-               if (curproxy->appsession_name != NULL) {
-                       //            Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
-                       //                  file, linenum);
-                       //            return 0;
-                       free(curproxy->appsession_name);
-               }
-       
                if (*(args[5]) == 0) {
                        Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout>.\n",
                              file, linenum, args[0]);
                        return -1;
                }
                have_appsession = 1;
+               free(curproxy->appsession_name);
                curproxy->appsession_name = strdup(args[1]);
                curproxy->appsession_name_len = strlen(curproxy->appsession_name);
                curproxy->appsession_len = atoi(args[3]);
@@ -1005,23 +982,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                        return 0;
 
                if (!strcmp(args[1], "cookie")) {  /* name of a cookie to capture */
-                       //        if (curproxy == &defproxy) {
-                       //            Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
-                       //            return -1;
-                       //        }
-
-                       if (curproxy->capture_name != NULL) {
-                               //     Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
-                               //           file, linenum, args[0]);
-                               //     return 0;
-                               free(curproxy->capture_name);
-                       }
-       
                        if (*(args[4]) == 0) {
                                Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
                                      file, linenum, args[0]);
                                return -1;
                        }
+                       free(curproxy->capture_name);
                        curproxy->capture_name = strdup(args[2]);
                        curproxy->capture_namelen = strlen(curproxy->capture_name);
                        curproxy->capture_len = atol(args[4]);
@@ -1378,9 +1344,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                        if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
                                return 0;
                        /* use HTTP request to check servers' health */
-                       if (curproxy->check_req != NULL) {
-                               free(curproxy->check_req);
-                       }
+                       free(curproxy->check_req);
                        curproxy->options &= ~PR_O_SSL3_CHK;
                        curproxy->options &= ~PR_O_SMTP_CHK;
                        curproxy->options |= PR_O_HTTP_CHK;
@@ -1409,18 +1373,14 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                        if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
                                return 0;
 
-                       if (curproxy->check_req != NULL) {
-                               free(curproxy->check_req);
-                       }
+                       free(curproxy->check_req);
                        curproxy->options &= ~PR_O_HTTP_CHK;
                        curproxy->options &= ~PR_O_SMTP_CHK;
                        curproxy->options |= PR_O_SSL3_CHK;
                }
                else if (!strcmp(args[1], "smtpchk")) {
                        /* use SMTP request to check servers' health */
-                       if (curproxy->check_req != NULL) {
-                               free(curproxy->check_req);
-                       }
+                       free(curproxy->check_req);
                        curproxy->options &= ~PR_O_HTTP_CHK;
                        curproxy->options &= ~PR_O_SSL3_CHK;
                        curproxy->options |= PR_O_SMTP_CHK;
@@ -1501,8 +1461,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                        Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
                        return -1;
                }
-               if (curproxy->defbe.name)
-                       free(curproxy->defbe.name);
+               free(curproxy->defbe.name);
                curproxy->defbe.name = strdup(args[1]);
        }
        else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
@@ -2617,8 +2576,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
 
                for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
                        if (http_err_codes[rc] == errnum) {
-                               if (curproxy->errmsg[rc].str)
-                                       free(curproxy->errmsg[rc].str);
+                               free(curproxy->errmsg[rc].str);
                                curproxy->errmsg[rc].str = err;
                                curproxy->errmsg[rc].len = errlen;
                                break;
@@ -2675,8 +2633,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                errnum = atol(args[1]);
                for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
                        if (http_err_codes[rc] == errnum) {
-                               if (curproxy->errmsg[rc].str)
-                                       free(curproxy->errmsg[rc].str);
+                               free(curproxy->errmsg[rc].str);
                                curproxy->errmsg[rc].str = err;
                                curproxy->errmsg[rc].len = errlen;
                                break;
@@ -2856,14 +2813,12 @@ int readcfgfile(const char *file)
                    !strcmp(args[0], "ruleset") ||
                    !strcmp(args[0], "defaults")) { /* new proxy */
                        confsect = CFG_LISTEN;
-                       if (cursection)
-                               free(cursection);
+                       free(cursection);
                        cursection = strdup(args[0]);
                }
                else if (!strcmp(args[0], "global")) { /* global config */
                        confsect = CFG_GLOBAL;
-                       if (cursection)
-                               free(cursection);
+                       free(cursection);
                        cursection = strdup(args[0]);
                }
                /* else it's a section keyword */
@@ -2882,8 +2837,7 @@ int readcfgfile(const char *file)
                        goto err;
                }
        }
-       if (cursection)
-               free(cursection);
+       free(cursection);
        cursection = NULL;
        fclose(f);
 
@@ -3284,14 +3238,12 @@ int readcfgfile(const char *file)
                }
        }
 
-       if (cursection)
-               free(cursection);
+       free(cursection);
        cursection = NULL;
        return 0;
 
  err:
-       if (cursection)
-               free(cursection);
+       free(cursection);
        cursection = NULL;
        return -1;
 }
index 30862cabcb006cd6e746c64981d4257d2d4aabcb..fdb31ec13e2317219fa0522fff24f80599b16c96 100644 (file)
@@ -325,14 +325,10 @@ REGPRM1 static void _do_term(struct poller *p)
 {
        fd_flush_changes();
 
-       if (chg_ptr)
-               free(chg_ptr);
-       if (chg_list)
-               free(chg_list);
-       if (fd_evts)
-               free(fd_evts);
-       if (epoll_events)
-               free(epoll_events);
+       free(chg_ptr);
+       free(chg_list);
+       free(fd_evts);
+       free(epoll_events);
 
        close(epoll_fd);
        epoll_fd = 0;
index 1e10b427f572044be65afc32e3702c22c4dfabf3..f5201060502aa11d25b47bf967a6932eea94f628 100644 (file)
@@ -199,12 +199,9 @@ REGPRM1 static int _do_init(struct poller *p)
  */
 REGPRM1 static void _do_term(struct poller *p)
 {
-       if (fd_evts[DIR_WR])
-               free(fd_evts[DIR_WR]);
-       if (fd_evts[DIR_RD])
-               free(fd_evts[DIR_RD]);
-       if (kev)
-               free(kev);
+       free(fd_evts[DIR_WR]);
+       free(fd_evts[DIR_RD]);
+       free(kev);
        close(kqueue_fd);
        kqueue_fd = 0;
 
index 4a1eb8bf93b51a4fde6c92c9403a89b5ac3c7eaf..a86c59991669663d181d228eb59f65d2aaf8f5d4 100644 (file)
@@ -207,12 +207,9 @@ REGPRM1 static int _do_init(struct poller *p)
  */
 REGPRM1 static void _do_term(struct poller *p)
 {
-       if (fd_evts[DIR_WR])
-               free(fd_evts[DIR_WR]);
-       if (fd_evts[DIR_RD])
-               free(fd_evts[DIR_RD]);
-       if (poll_events)
-               free(poll_events);
+       free(fd_evts[DIR_WR]);
+       free(fd_evts[DIR_RD]);
+       free(poll_events);
        p->private = NULL;
        p->pref = 0;
 }
index 90754050da8517eae88bf2fd768fbd9f8d3bd153..7fe7c239984c9011d283dbf22cec55c83e41cf50 100644 (file)
@@ -202,14 +202,10 @@ REGPRM1 static int _do_init(struct poller *p)
  */
 REGPRM1 static void _do_term(struct poller *p)
 {
-       if (fd_evts[DIR_WR])
-               free(fd_evts[DIR_WR]);
-       if (fd_evts[DIR_RD])
-               free(fd_evts[DIR_RD]);
-       if (tmp_evts[DIR_WR])
-               free(tmp_evts[DIR_WR]);
-       if (tmp_evts[DIR_RD])
-               free(tmp_evts[DIR_RD]);
+       free(fd_evts[DIR_WR]);
+       free(fd_evts[DIR_RD]);
+       free(tmp_evts[DIR_WR]);
+       free(tmp_evts[DIR_RD]);
        p->private = NULL;
        p->pref = 0;
 }
index 70b10655d1f98cca004dcf5590d11169dc4de8dd..9fedbdc88ab4346a18e31b88f6c442d8770999a1 100644 (file)
@@ -541,12 +541,9 @@ REGPRM1 static int _do_init(struct poller *p)
  */
 REGPRM1 static void _do_term(struct poller *p)
 {
-       if (fd_list)
-               free(fd_list);
-       if (spec_list)
-               free(spec_list);
-       if (epoll_events)
-               free(epoll_events);
+       free(fd_list);
+       free(spec_list);
+       free(epoll_events);
 
        close(epoll_fd);
        epoll_fd = 0;
index 9ef07f29fc831fbe20d150334914970668f66ffd..c936bf05f7e610a85e2087db2d107dfc0dfd22ce 100644 (file)
@@ -547,8 +547,7 @@ void init(int argc, char **argv)
                global.maxconn = cfg_maxconn;
 
        if (cfg_pidfile) {
-               if (global.pidfile)
-                       free(global.pidfile);
+               free(global.pidfile);
                global.pidfile = strdup(cfg_pidfile);
        }
 
@@ -645,41 +644,22 @@ void deinit(void)
        int i;
 
        while (p) {
-               if (p->id)
-                       free(p->id);
-
-               if (p->check_req)
-                       free(p->check_req);
-
-               if (p->cookie_name)
-                       free(p->cookie_name);
-
-               if (p->cookie_domain)
-                       free(p->cookie_domain);
-
-               if (p->url_param_name)
-                       free(p->url_param_name);
+               free(p->id);
+               free(p->check_req);
+               free(p->cookie_name);
+               free(p->cookie_domain);
+               free(p->url_param_name);
+               free(p->capture_name);
+               free(p->monitor_uri);
 
-               if (p->capture_name)
-                       free(p->capture_name);
+               for (i = 0; i < HTTP_ERR_SIZE; i++)
+                       free(p->errmsg[i].str);
 
-               if (p->monitor_uri)
-                       free(p->monitor_uri);
-
-               for (i = 0; i < HTTP_ERR_SIZE; i++) {
-                       if (p->errmsg[i].len)
-                               free(p->errmsg[i].str);
-               }
-
-               for (i = 0; i < p->nb_reqadd; i++) {
-                       if (p->req_add[i])
-                               free(p->req_add[i]);
-               }
+               for (i = 0; i < p->nb_reqadd; i++)
+                       free(p->req_add[i]);
 
-               for (i = 0; i < p->nb_rspadd; i++) {
-                       if (p->rsp_add[i])
-                               free(p->rsp_add[i]);
-               }
+               for (i = 0; i < p->nb_rspadd; i++)
+                       free(p->rsp_add[i]);
 
                list_for_each_entry_safe(cond, condb, &p->block_cond, list) {
                        LIST_DEL(&cond->list);
@@ -743,10 +723,8 @@ void deinit(void)
 
                list_for_each_entry_safe(rule, ruleb, &p->switching_rules, list) {
                        LIST_DEL(&rule->list);
-
                        prune_acl_cond(rule->cond);
                        free(rule->cond);
-
                        free(rule);
                }
 
@@ -758,14 +736,12 @@ void deinit(void)
                        free(rdr);
                }
 
-               if (p->appsession_name)
-                       free(p->appsession_name);
+               free(p->appsession_name);
 
                h = p->req_cap;
                while (h) {
                        h_next = h->next;
-                       if (h->name)
-                               free(h->name);
+                       free(h->name);
                        pool_destroy2(h->pool);
                        free(h);
                        h = h_next;
@@ -774,9 +750,7 @@ void deinit(void)
                h = p->rsp_cap;
                while (h) {
                        h_next = h->next;
-                       if (h->name)
-                               free(h->name);
-           
+                       free(h->name);
                        pool_destroy2(h->pool);
                        free(h);
                        h = h_next;
@@ -791,12 +765,8 @@ void deinit(void)
                                task_free(s->check);
                        }
 
-                       if (s->id)
-                               free(s->id);
-           
-                       if (s->cookie)
-                               free(s->cookie);
-           
+                       free(s->id);
+                       free(s->cookie);
                        free(s);
                        s = s_next;
                }/* end while(s) */
@@ -820,36 +790,24 @@ void deinit(void)
                uap = ua;
                ua = ua->next;
 
-               if (uap->uri_prefix)
-                       free(uap->uri_prefix);
-
-               if (uap->auth_realm)
-                       free(uap->auth_realm);
+               free(uap->uri_prefix);
+               free(uap->auth_realm);
 
                while (uap->users) {
                        user = uap->users;
                        uap->users = uap->users->next;
-
                        free(user->user_pwd);
                        free(user);
                }
-
                free(uap);
        }
 
        protocol_unbind_all();
 
-       if (global.chroot)    free(global.chroot);
-       global.chroot = NULL;
-
-       if (global.pidfile)   free(global.pidfile);
-       global.pidfile = NULL;
-    
-       if (fdtab)            free(fdtab);
-       fdtab = NULL;
-
-       if (oldpids)
-               free(oldpids);
+       free(global.chroot);  global.chroot = NULL;
+       free(global.pidfile); global.pidfile = NULL;
+       free(fdtab);          fdtab   = NULL;
+       free(oldpids);        oldpids = NULL;
 
        pool_destroy2(pool2_session);
        pool_destroy2(pool2_buffer);
index 8ac618cc373a2fcad43a56610668cda0d2fb8c88..67e237a65b30f6a6c6813622853766de12f9ab9b 100644 (file)
@@ -73,11 +73,9 @@ struct uri_auth *stats_set_uri(struct uri_auth **root, char *uri)
        if ((u = stats_check_init_uri_auth(root)) == NULL)
                goto out_u;
        
-       if (u->uri_prefix)
-               free(u->uri_prefix);
-
-       u->uri_len = uri_len;
+       free(u->uri_prefix);
        u->uri_prefix = uri_copy;
+       u->uri_len = uri_len;
        return u;
 
  out_u:
@@ -101,9 +99,7 @@ struct uri_auth *stats_set_realm(struct uri_auth **root, char *realm)
        if ((u = stats_check_init_uri_auth(root)) == NULL)
                goto out_u;
        
-       if (u->auth_realm)
-               free(u->auth_realm);
-
+       free(u->auth_realm);
        u->auth_realm = realm_copy;
        return u;