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

(cherry picked from commit 9139ec34ed7aae4fe63926ca5c87a5b32b376488)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 4d3c8ad..f1d5a41 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -931,7 +931,6 @@
 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 @@
 		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 @@
 		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 @@
 			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 @@
 			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 @@
 			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;