]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-cli: fix memory leak in list_ctrl()
authorMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 10:46:12 +0000 (19:46 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 10:46:12 +0000 (19:46 +0900)
Fix memory leak of _cntlist_ cause a memory leak below.

==7724== HEAP SUMMARY:
==7724==     in use at exit: 4,096 bytes in 1 blocks
==7724==   total heap usage: 31 allocs, 30 frees, 7,871 bytes allocated
==7724==
==7724== Searching for pointers to 1 not-freed blocks
==7724== Checked 70,624 bytes
==7724==
==7724== 4,096 bytes in 1 blocks are definitely lost in loss record 1 of 1
==7724==    at 0x4C2FFC6: memalign (in
                          /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7724==    by 0x4C300D1: posix_memalign (in
                          /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7724==    by 0x408354: list_ctrl (nvme.c:573)
==7724==    by 0x419587: handle_plugin (plugin.c:150)
==7724==    by 0x401890: main (nvme.c:3799)
==7724==
==7724== LEAK SUMMARY:
==7724==    definitely lost: 4,096 bytes in 1 blocks
==7724==    indirectly lost: 0 bytes in 0 blocks
==7724==      possibly lost: 0 bytes in 0 blocks
==7724==    still reachable: 0 bytes in 0 blocks
==7724==         suppressed: 0 bytes in 0 blocks

==7724== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index a6f0639ded1eac962bbdc3f09681ac9b0ee0a149..5fe99ce952f11d6a1794945657524985fe5078e2 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -587,6 +587,9 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *
                        nvme_status_to_string(err), err, cfg.cntid);
        else
                perror("id controller list");
+
+       free(cntlist);
+
        return err;
 }