libxtables: make iptables and ip6tables use xtables_free_opts
The patch modifies xtables_globals to introduce orig_opts and
xtables_free_opts() to emulate what free_opts used to do. We also get
rid of the copies of free_opts() that iptables and ip6tables keep.
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
diff --git a/ip6tables.c b/ip6tables.c
index 19c3258..f7a882e 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -150,6 +150,7 @@
.option_offset = 0,
.program_version = IPTABLES_VERSION,
.opts = original_opts,
+ .orig_opts = original_opts,
.exit_err = ip6tables_exit_error,
};
@@ -224,16 +225,6 @@
return NULL;
}
-static void free_opts(int reset_offset)
-{
- if (opts != original_opts) {
- free(opts);
- opts = original_opts;
- if (reset_offset)
- global_option_offset = 0;
- }
-}
-
static void
exit_tryhelp(int status)
{
@@ -241,7 +232,7 @@
fprintf(stderr, "Error occurred at line: %d\n", line);
fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
program_name, program_name );
- free_opts(1);
+ xtables_free_opts(1);
exit(status);
}
@@ -351,7 +342,7 @@
fprintf(stderr,
"Perhaps ip6tables or your kernel needs to be upgraded.\n");
/* On error paths, make sure that we don't leak memory */
- free_opts(1);
+ xtables_free_opts(1);
exit(status);
}
@@ -530,7 +521,7 @@
merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
memcpy(merge, oldopts, num_old * sizeof(struct option));
- free_opts(0); /* Release previous options merged if any */
+ xtables_free_opts(0); /* Release previous options merged if any */
for (i = 0; i < num_new; i++) {
merge[num_old + i] = newopts[i];
merge[num_old + i].val += *option_offset;
@@ -2048,7 +2039,7 @@
for (i = 0; i < ndaddrs; i++)
free(&daddrs[i]);
- free_opts(1);
+ xtables_free_opts(1);
return ret;
}