From 4dd5fedadee415a646bc0e70d0b17668897ede63 Mon Sep 17 00:00:00 2001 From: Martin Josefsson Date: Tue, 18 May 2004 18:09:43 +0000 Subject: Get rid of some memoryleaks. Will make ip(6)tables-restore sessions use less memory. --- ip6tables.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'ip6tables.c') diff --git a/ip6tables.c b/ip6tables.c index 9e9a5290..b2816bad 100644 --- a/ip6tables.c +++ b/ip6tables.c @@ -1433,6 +1433,8 @@ delete_entry(const ip6t_chainlabel chain, ret &= ip6tc_delete_entry(chain, fw, mask, handle); } } + free(mask); + return ret; } @@ -1654,6 +1656,8 @@ void clear_rule_matches(struct ip6tables_rule_match **matches) for (matchp = *matches; matchp;) { tmp = matchp->next; + if (matchp->match->m) + free(matchp->match->m); free(matchp); matchp = tmp; } @@ -1688,9 +1692,6 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle) memset(&fw, 0, sizeof(fw)); - opts = original_opts; - global_option_offset = 0; - /* re-set optind to 0 in case do_command gets called * a second time */ optind = 0; @@ -2196,6 +2197,9 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle) printf("Warning: using chain %s, not extension\n", jumpto); + if (target->t) + free(target->t); + target = NULL; } @@ -2225,6 +2229,7 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle) find_target(jumpto, LOAD_MUST_SUCCEED); } else { e = generate_entry(&fw, matches, target->t); + free(target->t); } } @@ -2302,5 +2307,22 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle) clear_rule_matches(&matches); + if (e != NULL) { + free(e); + e = NULL; + } + + for (c = 0; c < nsaddrs; c++) + free(&saddrs[c]); + + for (c = 0; c < ndaddrs; c++) + free(&daddrs[c]); + + if (opts != original_opts) { + free(opts); + opts = original_opts; + global_option_offset = 0; + } + return ret; } -- cgit v1.2.3