Commit 40503ba5 authored by Matthieu Boutier's avatar Matthieu Boutier Committed by Juliusz Chroboczek

Fix parser memory leaks.

parent 4f4e3cba
...@@ -320,6 +320,17 @@ get_interface_type(int c, int *type_r, gnc_t gnc, void *closure) ...@@ -320,6 +320,17 @@ get_interface_type(int c, int *type_r, gnc_t gnc, void *closure)
return c; return c;
} }
static void
free_filter(struct filter *f)
{
free(f->ifname);
free(f->id);
free(f->prefix);
free(f->src_prefix);
free(f->neigh);
free(f->action.src_prefix);
free(f);
}
static int static int
parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return) parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return)
...@@ -341,7 +352,7 @@ parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return) ...@@ -341,7 +352,7 @@ parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return)
} }
c = getword(c, &token, gnc, closure); c = getword(c, &token, gnc, closure);
if(c < -1) { if(c < -1) {
free(filter); free_filter(filter);
return -2; return -2;
} }
...@@ -478,7 +489,7 @@ parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return) ...@@ -478,7 +489,7 @@ parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return)
error: error:
free(token); free(token);
free(filter); free_filter(filter);
return -2; return -2;
} }
...@@ -619,6 +630,8 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure, ...@@ -619,6 +630,8 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure,
return c; return c;
error: error:
if(if_conf->ifname)
free(if_conf->ifname);
free(if_conf); free(if_conf);
return -2; return -2;
} }
...@@ -711,6 +724,7 @@ add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs) ...@@ -711,6 +724,7 @@ add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs)
while(next) { while(next) {
if(strcmp(next->ifname, if_conf->ifname) == 0) { if(strcmp(next->ifname, if_conf->ifname) == 0) {
merge_ifconf(next, if_conf, next); merge_ifconf(next, if_conf, next);
free(if_conf->ifname);
free(if_conf); free(if_conf);
if_conf = next; if_conf = next;
goto done; goto done;
...@@ -732,6 +746,7 @@ flush_ifconf(struct interface_conf *if_conf) ...@@ -732,6 +746,7 @@ flush_ifconf(struct interface_conf *if_conf)
{ {
if(if_conf == interface_confs) { if(if_conf == interface_confs) {
interface_confs = if_conf->next; interface_confs = if_conf->next;
free(if_conf->ifname);
free(if_conf); free(if_conf);
return; return;
} else { } else {
...@@ -739,6 +754,7 @@ flush_ifconf(struct interface_conf *if_conf) ...@@ -739,6 +754,7 @@ flush_ifconf(struct interface_conf *if_conf)
while(prev) { while(prev) {
if(prev->next == if_conf) { if(prev->next == if_conf) {
prev->next = if_conf->next; prev->next = if_conf->next;
free(if_conf->ifname);
free(if_conf); free(if_conf);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment