summaryrefslogtreecommitdiff
path: root/usr.sbin/dhcpd
diff options
context:
space:
mode:
authorzinovik <zinovik@cvs.openbsd.org>2010-04-02 17:03:59 +0000
committerzinovik <zinovik@cvs.openbsd.org>2010-04-02 17:03:59 +0000
commit921b6b94312c0b13ae024f50d77ab920127bf2d7 (patch)
tree07130234870a5e3831e284b8ae1cba332970c695 /usr.sbin/dhcpd
parenta5d1ae77c4f33388c4269b5f785cf9721fe8225f (diff)
plug memory leaks on error paths
joint work with krw@ ok krw@, stsp@
Diffstat (limited to 'usr.sbin/dhcpd')
-rw-r--r--usr.sbin/dhcpd/confpars.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index 2851070648c..1d8a50af9e8 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confpars.c,v 1.19 2010/03/27 14:11:38 krw Exp $ */
+/* $OpenBSD: confpars.c,v 1.20 2010/04/02 17:03:58 zinovik Exp $ */
/*
* Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
@@ -520,8 +520,12 @@ void parse_host_declaration(cfile, group)
host->name = name;
host->group = clone_group(group, "parse_host_declaration");
- if (!parse_lbrace(cfile))
+ if (!parse_lbrace(cfile)) {
+ free(host->name);
+ free(host->group);
+ free(host);
return;
+ }
do {
token = peek_token(&val, cfile);
@@ -583,8 +587,12 @@ void parse_class_declaration(cfile, group, type)
error("No memory for class %s.", val);
class->group = clone_group(group, "parse_class_declaration");
- if (!parse_lbrace(cfile))
+ if (!parse_lbrace(cfile)) {
+ free(class->name);
+ free(class->group);
+ free(class);
return;
+ }
do {
token = peek_token(&val, cfile);
@@ -640,19 +648,29 @@ void parse_shared_net_declaration(cfile, group)
error("no memory for shared network name");
} else {
name = parse_host_name(cfile);
- if (!name)
+ if (!name) {
+ free(share->group);
+ free(share);
return;
+ }
}
share->name = name;
- if (!parse_lbrace(cfile))
+ if (!parse_lbrace(cfile)) {
+ free(share->group);
+ free(share->name);
+ free(share);
return;
+ }
do {
token = peek_token(&val, cfile);
if (token == '}') {
token = next_token(&val, cfile);
if (!share->subnets) {
+ free(share->group);
+ free(share->name);
+ free(share);
parse_warn("empty shared-network decl");
return;
}
@@ -692,22 +710,30 @@ void parse_subnet_declaration(cfile, share)
subnet->group->subnet = subnet;
/* Get the network number... */
- if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8)) {
+ free(subnet->group);
+ free(subnet);
return;
+ }
memcpy(iaddr.iabuf, addr, len);
iaddr.len = len;
subnet->net = iaddr;
token = next_token(&val, cfile);
if (token != TOK_NETMASK) {
+ free(subnet->group);
+ free(subnet);
parse_warn("Expecting netmask");
skip_to_semi(cfile);
return;
}
/* Get the netmask... */
- if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8))
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8)) {
+ free(subnet->group);
+ free(subnet);
return;
+ }
memcpy(iaddr.iabuf, addr, len);
iaddr.len = len;
subnet->netmask = iaddr;
@@ -769,8 +795,10 @@ void parse_group_declaration(cfile, group)
g = clone_group(group, "parse_group_declaration");
- if (!parse_lbrace(cfile))
+ if (!parse_lbrace(cfile)) {
+ free(g);
return;
+ }
do {
token = peek_token(&val, cfile);
@@ -908,6 +936,7 @@ void parse_option_param(cfile, group)
parse_warn("expecting identifier after '.'");
if (token != ';')
skip_to_semi(cfile);
+ free(vendor);
return;
}
@@ -920,6 +949,7 @@ void parse_option_param(cfile, group)
if (!universe) {
parse_warn("no vendor named %s.", vendor);
skip_to_semi(cfile);
+ free(vendor);
return;
}
} else {
@@ -941,6 +971,7 @@ void parse_option_param(cfile, group)
parse_warn("no option named %s for vendor %s",
val, vendor);
skip_to_semi(cfile);
+ free(vendor);
return;
}