]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
examples: Fix memory leaks detected by Valgrind
authorShyam Saini <mayhs11saini@gmail.com>
Tue, 29 Aug 2017 12:49:36 +0000 (18:19 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 4 Sep 2017 20:49:15 +0000 (22:49 +0200)
==11688== HEAP SUMMARY:
==11688==     in use at exit: 40 bytes in 1 blocks
==11688==   total heap usage: 7 allocs, 6 frees, 220 bytes allocated
==11688==
==11688== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==11688==    at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11688==    by 0x5068955: mnl_nlmsg_batch_start (nlmsg.c:441)
==11688==    by 0x40133B: main (nft-chain-add.c:103)
==11688==
==11688== LEAK SUMMARY:
==11688==    definitely lost: 40 bytes in 1 blocks
==11688==    indirectly lost: 0 bytes in 0 blocks
==11688==      possibly lost: 0 bytes in 0 blocks
==11688==    still reachable: 0 bytes in 0 blocks
==11688==         suppressed: 0 bytes in 0 blocks

==11831== HEAP SUMMARY:
==11831==     in use at exit: 40 bytes in 1 blocks
==11831==   total heap usage: 7 allocs, 6 frees, 220 bytes allocated
==11831==
==11831== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==11831==    at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11831==    by 0x5068955: mnl_nlmsg_batch_start (nlmsg.c:441)
==11831==    by 0x401154: main (nft-chain-del.c:79)
==11831==
==11831== LEAK SUMMARY:
==11831==    definitely lost: 40 bytes in 1 blocks
==11831==    indirectly lost: 0 bytes in 0 blocks
==11831==      possibly lost: 0 bytes in 0 blocks
==11831==    still reachable: 0 bytes in 0 blocks
==11831==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
examples/nft-chain-add.c
examples/nft-chain-del.c
examples/nft-chain-parse-add.c

index ca1edf9e6f86892d133e8e187f7a86be7391a0ad..e0d889df40eb147754dc49104490d3351ec84424 100644 (file)
@@ -138,6 +138,8 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
+       mnl_nlmsg_batch_stop(batch);
+
        ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
        while (ret > 0) {
                ret = mnl_cb_run(buf, ret, chain_seq, portid, NULL, NULL);
index b756b46f9bbd4b5a826778ecbf9a29b6c378c938..e99bb8a2474fc4b7ce8d6d50dd83af7785c53043 100644 (file)
@@ -114,6 +114,8 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
+       mnl_nlmsg_batch_stop(batch);
+
        ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
        while (ret > 0) {
                ret = mnl_cb_run(buf, ret, chain_seq, portid, NULL, NULL);
index 6d6d989cd81dbdeb94f39340178c7fc583b94e66..a9ee8e9259b2dbdbc28373d1186c303776871a8f 100644 (file)
@@ -149,6 +149,8 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
+       mnl_nlmsg_batch_stop(batch);
+
        ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
        while (ret > 0) {
                ret = mnl_cb_run(buf, ret, chain_seq, portid, NULL, NULL);