summaryrefslogtreecommitdiff
path: root/src/iptables.c
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2013-02-21 17:42:29 +0100
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-22 12:42:49 +0200
commitbdd1663c5cf56853ca745635f7448e09613d5e36 (patch)
treeb26f0840f703d6782540e84353f03274e8bfbfe5 /src/iptables.c
parent549278f755c026e0282ec5bcb5e9c001705dcbca (diff)
downloadconnman-bdd1663c5cf56853ca745635f7448e09613d5e36.tar.gz
connman-bdd1663c5cf56853ca745635f7448e09613d5e36.tar.bz2
connman-bdd1663c5cf56853ca745635f7448e09613d5e36.zip
iptables: Reinitialize global parser table
xtables modifies the global parse table and allocates additional memory. If that happens we need to free it afterwards.
Diffstat (limited to 'src/iptables.c')
-rw-r--r--src/iptables.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/iptables.c b/src/iptables.c
index 7376792f..4d46a5b9 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -2030,6 +2030,20 @@ out:
return err;
}
+static void reset_xtables(void)
+{
+ /*
+ * We need also to free the memory implicitly allocated
+ * during parsing (see xtables_options_xfrm()).
+ * Note xt_params is actually iptables_globals.
+ */
+ if (xt_params->opts != xt_params->orig_opts) {
+ g_free(xt_params->opts);
+ xt_params->opts = xt_params->orig_opts;
+ }
+ xt_params->option_offset = 0;
+}
+
static void cleanup_parse_context(struct parse_context *ctx)
{
g_strfreev(ctx->argv);
@@ -2136,6 +2150,7 @@ int __connman_iptables_append(const char *table_name,
target_name, ctx->xt_t, ctx->xt_rm);
out:
cleanup_parse_context(ctx);
+ reset_xtables();
return err;
}
@@ -2179,6 +2194,7 @@ int __connman_iptables_delete(const char *table_name,
ctx->xt_rm);
out:
cleanup_parse_context(ctx);
+ reset_xtables();
return err;
}
@@ -2291,6 +2307,4 @@ void __connman_iptables_cleanup(void)
DBG("");
g_hash_table_destroy(table_hash);
-
- xtables_free_opts(1);
}