]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-cli: fix memory leak in sec_recv()
authorMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 11:26:37 +0000 (20:26 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 11:26:37 +0000 (20:26 +0900)
Fix memory leak for _sec_buf_.

==7670== HEAP SUMMARY:
==7670==     in use at exit: 4,096 bytes in 1 blocks
==7670==   total heap usage: 31 allocs, 30 frees, 8,046 bytes allocated
==7670==
==7670== Searching for pointers to 1 not-freed blocks
==7670== Checked 70,656 bytes
==7670==
==7670== 4,096 bytes in 1 blocks are definitely lost in loss record 1 of
1
==7670==    at 0x4C2FFC6: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7670==    by 0x4C300D1: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7670==    by 0x4056F3: sec_recv (nvme.c:3391)
==7670==    by 0x419587: handle_plugin (plugin.c:150)
==7670==    by 0x401890: main (nvme.c:3799)
==7670==
==7670== LEAK SUMMARY:
==7670==    definitely lost: 4,096 bytes in 1 blocks
==7670==    indirectly lost: 0 bytes in 0 blocks
==7670==      possibly lost: 0 bytes in 0 blocks
==7670==    still reachable: 0 bytes in 0 blocks
==7670==         suppressed: 0 bytes in 0 blocks
==7670==
==7670== 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 4b3073e749846d85c2c32cfc1e73f52ca1d89796..bb0f77f731ef1fd3bb3cc2f7f91dbc702a978269 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3431,6 +3431,9 @@ static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *p
                } else if (cfg.size)
                        d_raw((unsigned char *)sec_buf, cfg.size);
        }
+
+       free(sec_buf);
+
        return err;
 }