]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables: Allocate rule cache just once
authorPhil Sutter <phil@nwl.cc>
Thu, 2 Aug 2018 15:05:08 +0000 (17:05 +0200)
committerFlorian Westphal <fw@strlen.de>
Sat, 4 Aug 2018 12:07:23 +0000 (14:07 +0200)
For each parsed table, xtables-restore calls nft_table_flush() which
each time allocates a new rule cache, possibly overwriting the pointer
to the previously allocated one. Fix this by checking the pointer value
and only allocate if it's NULL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/nft.c

index a9cb92edbf1112723d41653518ab51cd38dd2945..d5c4c7661c3abf066c7b79ef4822e79f082db66e 100644 (file)
@@ -1867,9 +1867,11 @@ next:
                t = nftnl_table_list_iter_next(iter);
        }
 
-       h->rule_cache = nftnl_rule_list_alloc();
-       if (h->rule_cache == NULL)
-               return -1;
+       if (!h->rule_cache) {
+               h->rule_cache = nftnl_rule_list_alloc();
+               if (h->rule_cache == NULL)
+                       return -1;
+       }
 
 err_table_iter:
        nftnl_table_list_iter_destroy(iter);