]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Get rid of some memoryleaks.
authorMartin Josefsson <gandalf@wlug.westbo.se>
Tue, 18 May 2004 18:09:43 +0000 (18:09 +0000)
committerMartin Josefsson <gandalf@wlug.westbo.se>
Tue, 18 May 2004 18:09:43 +0000 (18:09 +0000)
Will make ip(6)tables-restore sessions use less memory.

ip6tables.c
iptables.c

index 9e9a5290a4e66d73889e1eb490ec8bf065a90b23..b2816bad7202c39957cb138631030d2a4121f3d4 100644 (file)
@@ -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;
 }
index 4b0fe6c1e0a16be3bdc23c3894143dd1c848ec29..bec912f4db0cc27cab04669ebe3d39514e282484 100644 (file)
@@ -1431,6 +1431,8 @@ delete_entry(const ipt_chainlabel chain,
                        ret &= iptc_delete_entry(chain, fw, mask, handle);
                }
        }
+       free(mask);
+
        return ret;
 }
 
@@ -1652,6 +1654,8 @@ void clear_rule_matches(struct iptables_rule_match **matches)
 
        for (matchp = *matches; matchp;) {
                tmp = matchp->next;
+               if (matchp->match->m)
+                       free(matchp->match->m);
                free(matchp);
                matchp = tmp;
        }
@@ -1685,9 +1689,6 @@ int do_command(int argc, char *argv[], char **table, iptc_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_command(int argc, char *argv[], char **table, iptc_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_command(int argc, char *argv[], char **table, iptc_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_command(int argc, char *argv[], char **table, iptc_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;
 }