]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse/proxy: Group alloc error handling during proxy section parsing
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 12 Apr 2021 19:31:45 +0000 (21:31 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 12 Apr 2021 20:04:19 +0000 (22:04 +0200)
All allocation errors in cfg_parse_listen() are now handled in a unique
place under the "alloc_error" label. This simplify a bit error handling in
this function.

src/cfgparse-listen.c

index 6d764cff537b9d317a48abbab4d826aa46f170d5..b2c81da611c7e111a8cef0862425dc747c443bf9 100644 (file)
@@ -387,11 +387,9 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                }
 
                bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW));
-               if (!bind_conf) {
-                       ha_alert("Out of memory error.\n");
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!bind_conf)
+                       goto alloc_error;
+
                /* use default settings for unix sockets */
                bind_conf->settings.ux.uid  = global.unix_bind.ux.uid;
                bind_conf->settings.ux.gid  = global.unix_bind.ux.gid;
@@ -496,11 +494,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                free(curproxy->monitor_uri);
                curproxy->monitor_uri_len = strlen(args[1]);
                curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
-               if (!curproxy->monitor_uri) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->monitor_uri)
+                       goto alloc_error;
                memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
                curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
 
@@ -586,11 +581,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        len += strlen(args[i]) + 1;
 
                d = calloc(1, len);
-               if (!d) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!d)
+                       goto alloc_error;
                curproxy->desc = d;
 
                d += snprintf(d, curproxy->desc + len - d, "%s", args[1]);
@@ -688,11 +680,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                ha_free(&curproxy->cookie_domain);
                free(curproxy->cookie_name);
                curproxy->cookie_name = strdup(args[1]);
-               if (!curproxy->cookie_name) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->cookie_name)
+                       goto alloc_error;
                curproxy->cookie_len = strlen(curproxy->cookie_name);
 
                cur_arg = 2;
@@ -758,12 +747,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                        memprintf(&curproxy->cookie_domain, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
                                }
 
-                               if (!curproxy->cookie_domain) {
-                                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                       err_code |= ERR_ALERT | ERR_ABORT;
-                                       goto out;
-                               }
-
+                               if (!curproxy->cookie_domain)
+                                       goto alloc_error;
                                cur_arg++;
                        }
                        else if (strcmp(args[cur_arg], "maxidle") == 0) {
@@ -863,11 +848,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                else
                                        memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]);
 
-                               if (!curproxy->cookie_attrs) {
-                                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                       err_code |= ERR_ALERT | ERR_ABORT;
-                                       goto out;
-                               }
+                               if (!curproxy->cookie_attrs)
+                                       goto alloc_error;
                                cur_arg++;
                        }
 
@@ -914,11 +896,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        }
                        free(curproxy->email_alert.from);
                        curproxy->email_alert.from = strdup(args[2]);
-                       if (!curproxy->email_alert.from) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->email_alert.from)
+                               goto alloc_error;
                }
                else if (strcmp(args[1], "mailers") == 0) {
                        if (*(args[1]) == 0) {
@@ -929,11 +908,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        }
                        free(curproxy->email_alert.mailers.name);
                        curproxy->email_alert.mailers.name = strdup(args[2]);
-                       if (!curproxy->email_alert.mailers.name) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->email_alert.mailers.name)
+                               goto alloc_error;
                }
                else if (strcmp(args[1], "myhostname") == 0) {
                        if (*(args[1]) == 0) {
@@ -944,11 +920,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        }
                        free(curproxy->email_alert.myhostname);
                        curproxy->email_alert.myhostname = strdup(args[2]);
-                       if (!curproxy->email_alert.myhostname) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->email_alert.myhostname)
+                               goto alloc_error;
                }
                else if (strcmp(args[1], "level") == 0) {
                        curproxy->email_alert.level = get_log_level(args[2]);
@@ -968,11 +941,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        }
                        free(curproxy->email_alert.to);
                        curproxy->email_alert.to = strdup(args[2]);
-                       if (!curproxy->email_alert.to) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->email_alert.to)
+                               goto alloc_error;
                }
                else {
                        ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n",
@@ -1012,21 +982,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
 
                                free(curproxy->rdp_cookie_name);
                                curproxy->rdp_cookie_name = my_strndup(beg, end - beg);
-                               if (!curproxy->rdp_cookie_name) {
-                                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                       err_code |= ERR_ALERT | ERR_ABORT;
-                                       goto out;
-                               }
+                               if (!curproxy->rdp_cookie_name)
+                                       goto alloc_error;
                                curproxy->rdp_cookie_len = end-beg;
                        }
                        else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */
                                free(curproxy->rdp_cookie_name);
                                curproxy->rdp_cookie_name = strdup("msts");
-                               if (!curproxy->rdp_cookie_name) {
-                                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                       err_code |= ERR_ALERT | ERR_ABORT;
-                                       goto out;
-                               }
+                               if (!curproxy->rdp_cookie_name)
+                                       goto alloc_error;
                                curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name);
                        }
                        else { /* syntax */
@@ -1080,11 +1044,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                else
                        curproxy->server_state_file_name = strdup(args[1]);
 
-               if (!curproxy->server_state_file_name) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->server_state_file_name)
+                       goto alloc_error;
        }
        else if (strcmp(args[0], "max-session-srv-conns") == 0) {
                if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
@@ -1119,11 +1080,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        }
                        free(curproxy->capture_name);
                        curproxy->capture_name = strdup(args[2]);
-                       if (!curproxy->capture_name) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->capture_name)
+                               goto alloc_error;
                        curproxy->capture_namelen = strlen(curproxy->capture_name);
                        curproxy->capture_len = atol(args[4]);
                        curproxy->to_log |= LW_COOKIE;
@@ -1162,9 +1120,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                if (hdr)
                                        ha_free(&hdr->name);
                                ha_free(&hdr);
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
+                               goto alloc_error;
                        }
                        hdr->index = curproxy->nb_req_cap++;
                        curproxy->req_cap = hdr;
@@ -1203,9 +1159,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                if (hdr)
                                        ha_free(&hdr->name);
                                ha_free(&hdr);
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
+                               goto alloc_error;
                        }
                        hdr->index = curproxy->nb_rsp_cap++;
                        curproxy->rsp_cap = hdr;
@@ -1339,11 +1293,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                /* set the desired header name, in lower case */
                free(curproxy->server_id_hdr_name);
                curproxy->server_id_hdr_name = strdup(args[1]);
-               if (!curproxy->server_id_hdr_name) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->server_id_hdr_name)
+                       goto alloc_error;
                curproxy->server_id_hdr_len  = strlen(curproxy->server_id_hdr_name);
                ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len));
        }
@@ -1427,9 +1378,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        if (rule)
                                ha_free(&(rule->be.name));
                        ha_free(&rule);
-                       ha_alert("Out of memory error.\n");
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
+                       goto alloc_error;
                }
                LIST_INIT(&rule->list);
                LIST_ADDQ(&curproxy->switching_rules, &rule->list);
@@ -1485,9 +1434,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        if (rule)
                                ha_free(&(rule->srv.name));
                        ha_free(&rule);
-                       ha_alert("Out of memory error.\n");
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
+                       goto alloc_error;
                }
                LIST_INIT(&rule->list);
                LIST_ADDQ(&curproxy->server_rules, &rule->list);
@@ -1530,9 +1477,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        if (cond)
                                prune_acl_cond(cond);
                        ha_free(&cond);
-                       ha_alert("Out of memory error.\n");
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
+                       goto alloc_error;
                }
                rule->cond = cond;
                if (strcmp(args[0], "force-persist") == 0) {
@@ -1700,9 +1645,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        if (cond)
                                prune_acl_cond(cond);
                        ha_free(&cond);
-                       ha_alert("Out of memory error.\n");
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
+                       goto alloc_error;
                }
                rule->cond = cond;
                rule->expr = expr;
@@ -1729,11 +1672,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                goto out;
                        }
 
-                       if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_check_init_uri_auth(&curproxy->uri_auth))
+                               goto alloc_error;
 
                        if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
                                ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n",
@@ -1757,9 +1697,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                if (cond)
                                        prune_acl_cond(cond);
                                ha_free(&cond);
-                               ha_alert("Out of memory error.\n");
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
+                               goto alloc_error;
                        }
                        rule->cond = cond;
                        LIST_INIT(&rule->list);
@@ -1769,21 +1707,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
-                       } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       } else if (!stats_set_uri(&curproxy->uri_auth, args[2]))
+                               goto alloc_error;
                } else if (strcmp(args[1], "realm") == 0) {
                        if (*(args[2]) == 0) {
                                ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
-                       } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       } else if (!stats_set_realm(&curproxy->uri_auth, args[2]))
+                               goto alloc_error;
                } else if (strcmp(args[1], "refresh") == 0) {
                        unsigned interval;
 
@@ -1805,11 +1737,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                         file, linenum, *err);
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
-                       } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       } else if (!stats_set_refresh(&curproxy->uri_auth, interval))
+                               goto alloc_error;
                } else if (strcmp(args[1], "http-request") == 0) {    /* request access control: allow/deny/auth */
                        struct act_rule *rule;
 
@@ -1819,11 +1748,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                goto out;
                        }
 
-                       if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_check_init_uri_auth(&curproxy->uri_auth))
+                               goto alloc_error;
 
                        if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) &&
                            !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) {
@@ -1849,45 +1775,27 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
-                       } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       } else if (!stats_add_auth(&curproxy->uri_auth, args[2]))
+                               goto alloc_error;
                } else if (strcmp(args[1], "scope") == 0) {
                        if (*(args[2]) == 0) {
                                ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
                                err_code |= ERR_ALERT | ERR_FATAL;
                                goto out;
-                       } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       } else if (!stats_add_scope(&curproxy->uri_auth, args[2]))
+                               goto alloc_error;
                } else if (strcmp(args[1], "enable") == 0) {
-                       if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_check_init_uri_auth(&curproxy->uri_auth))
+                               goto alloc_error;
                } else if (strcmp(args[1], "hide-version") == 0) {
-                       if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
-                               ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER))
+                               goto alloc_error;
                } else if (strcmp(args[1], "show-legends") == 0) {
-                       if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS))
+                               goto alloc_error;
                } else if (strcmp(args[1], "show-modules") == 0) {
-                       if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES))
+                               goto alloc_error;
                } else if (strcmp(args[1], "show-node") == 0) {
 
                        if (*args[2]) {
@@ -1910,11 +1818,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                }
                        }
 
-                       if (!stats_set_node(&curproxy->uri_auth, args[2])) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!stats_set_node(&curproxy->uri_auth, args[2]))
+                               goto alloc_error;
                } else if (strcmp(args[1], "show-desc") == 0) {
                        char *desc = NULL;
 
@@ -1938,9 +1843,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        else {
                                if (!stats_set_desc(&curproxy->uri_auth, desc)) {
                                        free(desc);
-                                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                       err_code |= ERR_ALERT | ERR_ABORT;
-                                       goto out;
+                                       goto alloc_error;
                                }
                                free(desc);
                        }
@@ -2291,11 +2194,8 @@ stats_error_parsing:
 
                        free(curproxy->fwdfor_hdr_name);
                        curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR);
-                       if (!curproxy->fwdfor_hdr_name) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->fwdfor_hdr_name)
+                               goto alloc_error;
                        curproxy->fwdfor_hdr_len  = strlen(DEF_XFORWARDFOR_HDR);
                        curproxy->except_xff_net.family = AF_UNSPEC;
 
@@ -2337,11 +2237,8 @@ stats_error_parsing:
                                        }
                                        free(curproxy->fwdfor_hdr_name);
                                        curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]);
-                                       if (!curproxy->fwdfor_hdr_name) {
-                                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                               err_code |= ERR_ALERT | ERR_ABORT;
-                                               goto out;
-                                       }
+                                       if (!curproxy->fwdfor_hdr_name)
+                                               goto alloc_error;
                                        curproxy->fwdfor_hdr_len  = strlen(curproxy->fwdfor_hdr_name);
                                        cur_arg += 2;
                                } else if (strcmp(args[cur_arg], "if-none") == 0) {
@@ -2367,11 +2264,8 @@ stats_error_parsing:
 
                        free(curproxy->orgto_hdr_name);
                        curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR);
-                       if (!curproxy->orgto_hdr_name) {
-                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                               err_code |= ERR_ALERT | ERR_ABORT;
-                               goto out;
-                       }
+                       if (!curproxy->orgto_hdr_name)
+                               goto alloc_error;
                        curproxy->orgto_hdr_len  = strlen(DEF_XORIGINALTO_HDR);
                        curproxy->except_xot_net.family = AF_UNSPEC;
 
@@ -2412,11 +2306,8 @@ stats_error_parsing:
                                        }
                                        free(curproxy->orgto_hdr_name);
                                        curproxy->orgto_hdr_name = strdup(args[cur_arg+1]);
-                                       if (!curproxy->orgto_hdr_name) {
-                                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                               err_code |= ERR_ALERT | ERR_ABORT;
-                                               goto out;
-                                       }
+                                       if (!curproxy->orgto_hdr_name)
+                                               goto alloc_error;
                                        curproxy->orgto_hdr_len  = strlen(curproxy->orgto_hdr_name);
                                        cur_arg += 2;
                                } else {
@@ -2452,11 +2343,8 @@ stats_error_parsing:
                }
                free(curproxy->defbe.name);
                curproxy->defbe.name = strdup(args[1]);
-               if (!curproxy->defbe.name) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->defbe.name)
+                       goto alloc_error;
 
                if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code))
                        goto out;
@@ -2748,11 +2636,8 @@ stats_error_parsing:
                }
                free(curproxy->conf.uniqueid_format_string);
                curproxy->conf.uniqueid_format_string = strdup(args[1]);
-               if (!curproxy->conf.uniqueid_format_string) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->conf.uniqueid_format_string)
+                       goto alloc_error;
 
                free(curproxy->conf.uif_file);
                curproxy->conf.uif_file = strdup(curproxy->conf.args.file);
@@ -2805,11 +2690,8 @@ stats_error_parsing:
                    curproxy->conf.logformat_string != clf_http_log_format)
                        free(curproxy->conf.logformat_string);
                curproxy->conf.logformat_string = strdup(args[1]);
-               if (!curproxy->conf.logformat_string) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->conf.logformat_string)
+                       goto alloc_error;
 
                free(curproxy->conf.lfs_file);
                curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
@@ -2839,11 +2721,8 @@ stats_error_parsing:
                if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
                        free(curproxy->conf.logformat_sd_string);
                curproxy->conf.logformat_sd_string = strdup(args[1]);
-               if (!curproxy->conf.logformat_sd_string) {
-                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                       err_code |= ERR_ALERT | ERR_ABORT;
-                       goto out;
-               }
+               if (!curproxy->conf.logformat_sd_string)
+                       goto alloc_error;
 
                free(curproxy->conf.lfsd_file);
                curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file);
@@ -2944,11 +2823,8 @@ stats_error_parsing:
                                        curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN;
                                        free(curproxy->conn_src.bind_hdr_name);
                                        curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1);
-                                       if (!curproxy->conn_src.bind_hdr_name) {
-                                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                               err_code |= ERR_ALERT | ERR_ABORT;
-                                               goto out;
-                                       }
+                                       if (!curproxy->conn_src.bind_hdr_name)
+                                               goto alloc_error;
                                        curproxy->conn_src.bind_hdr_len = end - name;
                                        memcpy(curproxy->conn_src.bind_hdr_name, name, end - name);
                                        curproxy->conn_src.bind_hdr_name[end-name] = '\0';
@@ -3010,11 +2886,8 @@ stats_error_parsing:
                                }
                                free(curproxy->conn_src.iface_name);
                                curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]);
-                               if (!curproxy->conn_src.iface_name) {
-                                       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
-                                       err_code |= ERR_ALERT | ERR_ABORT;
-                                       goto out;
-                               }
+                               if (!curproxy->conn_src.iface_name)
+                                       goto alloc_error;
                                curproxy->conn_src.iface_len  = strlen(curproxy->conn_src.iface_name);
                                global.last_checks |= LSTCHK_NETADM;
 #else
@@ -3195,4 +3068,9 @@ stats_error_parsing:
  out:
        free(errmsg);
        return err_code;
+
+ alloc_error:
+       ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
+       err_code |= ERR_ALERT | ERR_ABORT;
+       goto out;
 }