MEDIUM: init: use list_append_word in haproxy.c

replace LIST_ADDQ with list_append_word
This commit is contained in:
Maxime de Roucy 2016-05-13 23:52:55 +02:00 committed by Willy Tarreau
parent dc88785f9c
commit 0f503925f0

View File

@ -561,6 +561,7 @@ void init(int argc, char **argv)
char *tmp; char *tmp;
char *cfg_pidfile = NULL; char *cfg_pidfile = NULL;
int err_code = 0; int err_code = 0;
char *err_msg = NULL;
struct wordlist *wl; struct wordlist *wl;
char *progname; char *progname;
char *change_dir = NULL; char *change_dir = NULL;
@ -713,13 +714,12 @@ void init(int argc, char **argv)
/* now that's a cfgfile list */ /* now that's a cfgfile list */
argv++; argc--; argv++; argc--;
while (argc > 0) { while (argc > 0) {
wl = calloc(1, sizeof(*wl)); if (!list_append_word(&cfg_cfgfiles, *argv, &err_msg)) {
if (!wl) { Alert("Cannot load configuration file/directory %s : %s\n",
Alert("Cannot load configuration file %s : out of memory.\n", *argv); *argv,
err_msg);
exit(1); exit(1);
} }
wl->s = *argv;
LIST_ADDQ(&cfg_cfgfiles, &wl->list);
argv++; argc--; argv++; argc--;
} }
break; break;
@ -736,13 +736,12 @@ void init(int argc, char **argv)
case 'N' : cfg_maxpconn = atol(*argv); break; case 'N' : cfg_maxpconn = atol(*argv); break;
case 'L' : strncpy(localpeer, *argv, sizeof(localpeer) - 1); break; case 'L' : strncpy(localpeer, *argv, sizeof(localpeer) - 1); break;
case 'f' : case 'f' :
wl = calloc(1, sizeof(*wl)); if (!list_append_word(&cfg_cfgfiles, *argv, &err_msg)) {
if (!wl) { Alert("Cannot load configuration file/directory %s : %s\n",
Alert("Cannot load configuration file %s : out of memory.\n", *argv); *argv,
err_msg);
exit(1); exit(1);
} }
wl->s = *argv;
LIST_ADDQ(&cfg_cfgfiles, &wl->list);
break; break;
case 'p' : cfg_pidfile = *argv; break; case 'p' : cfg_pidfile = *argv; break;
default: usage(progname); default: usage(progname);
@ -1160,6 +1159,8 @@ void init(int argc, char **argv)
/* initialize structures for name resolution */ /* initialize structures for name resolution */
if (!dns_init_resolvers()) if (!dns_init_resolvers())
exit(1); exit(1);
free(err_msg);
} }
static void deinit_acl_cond(struct acl_cond *cond) static void deinit_acl_cond(struct acl_cond *cond)
@ -1550,6 +1551,7 @@ void deinit(void)
free(log); free(log);
} }
list_for_each_entry_safe(wl, wlb, &cfg_cfgfiles, list) { list_for_each_entry_safe(wl, wlb, &cfg_cfgfiles, list) {
free(wl->s);
LIST_DEL(&wl->list); LIST_DEL(&wl->list);
free(wl); free(wl);
} }