MINOR: cfgparse: tighten the scope of newnameserver variable, free it on error.

This should fix issue GH #931.

Also remove a misleading comment.

This commit can be backported as far as 1.9
This commit is contained in:
Eric Salama 2020-11-13 15:56:36 +01:00 committed by Christopher Faulet
parent fc633b6eff
commit 9139ec34ed

View File

@ -931,7 +931,6 @@ out:
int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
{
static struct dns_resolvers *curr_resolvers = NULL;
struct dns_nameserver *newnameserver = NULL;
const char *err;
int err_code = 0;
char *errmsg = NULL;
@ -992,6 +991,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
HA_SPIN_INIT(&curr_resolvers->lock);
}
else if (strcmp(args[0], "nameserver") == 0) { /* nameserver definition */
struct dns_nameserver *newnameserver = NULL;
struct sockaddr_storage *sk;
int port1, port2;
@ -1043,6 +1043,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
newnameserver->addr = *sk;
}
else if (strcmp(args[0], "parse-resolv-conf") == 0) {
struct dns_nameserver *newnameserver = NULL;
const char *whitespace = "\r\n\t ";
char *resolv_line = NULL;
int resolv_linenum = 0;
@ -1131,6 +1132,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
if (newnameserver->conf.file == NULL) {
ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
err_code |= ERR_ALERT | ERR_FATAL;
free(newnameserver);
goto resolv_out;
}
@ -1138,6 +1140,8 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
if (newnameserver->id == NULL) {
ha_alert("parsing [/etc/resolv.conf:%d] : out of memory.\n", resolv_linenum);
err_code |= ERR_ALERT | ERR_FATAL;
free((char *)newnameserver->conf.file);
free(newnameserver);
goto resolv_out;
}
@ -1287,7 +1291,7 @@ resolv_out:
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
} /* neither "nameserver" nor "resolvers" */
}
else if (*args[0] != 0) {
ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
err_code |= ERR_ALERT | ERR_FATAL;