]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
iptables: nft: fix memory leaks in nft_fini
authorAna Rey <anarey@gmail.com>
Mon, 2 Dec 2013 10:45:14 +0000 (11:45 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 30 Dec 2013 22:50:54 +0000 (23:50 +0100)
Those errors are shown with valgrind tool:

valgrind --leak-check=full xtables -A INPUT -i eth0 -p tcp --dport 80

==12554== 40 bytes in 1 blocks are still reachable in loss record 1 of 10
==12554==    at 0x4C2935B: malloc (vg_replace_malloc.c:270)
==12554==    by 0x574D755: mnl_nlmsg_batch_start (nlmsg.c:447)
==12554==    by 0x416520: nft_action (nft.c:2281)
==12554==    by 0x41355E: xtables_main (xtables-standalone.c:75)
==12554==    by 0x5B87994: (below main) (libc-start.c:260)

==12554== 135,168 bytes in 1 blocks are still reachable in loss record 9 of 10
==12554==    at 0x4C2935B: malloc (vg_replace_malloc.c:270)
==12554==    by 0x415A24: mnl_nft_batch_alloc (nft.c:102)
==12554==    by 0x416520: nft_action (nft.c:2281)
==12554==    by 0x41355E: xtables_main (xtables-standalone.c:75)
==12554==    by 0x5B87994: (below main) (libc-start.c:260)

These objects are allocated from nft_init but they were not released
appropriately in the exit path.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/nft.c

index 0599beb8cb13c0bc24f659614b79b829aac0720c..a015947fd4b5840e8622c417f497ed4db6e3fe0b 100644 (file)
@@ -618,6 +618,8 @@ int nft_init(struct nft_handle *h, struct builtin_table *t)
 void nft_fini(struct nft_handle *h)
 {
        mnl_socket_close(h->nl);
+       free(mnl_nlmsg_batch_head(h->batch));
+       mnl_nlmsg_batch_stop(h->batch);
 }
 
 int nft_table_add(struct nft_handle *h, const struct nft_table *t)