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

==10014== HEAP SUMMARY:
==10014==     in use at exit: 16 bytes in 1 blocks
==10014==   total heap usage: 52 allocs, 51 frees, 15,638 bytes
allocated
==10014==
==10014== Searching for pointers to 1 not-freed blocks
==10014== Checked 70,656 bytes
==10014==
==10014== 16 bytes in 1 blocks are definitely lost in loss record 1 of 1
==10014==    at 0x4C2FFC6: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10014==    by 0x4C300D1: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10014==    by 0x402733: dir_receive (nvme.c:3531)
==10014==    by 0x4192A7: handle_plugin (plugin.c:150)
==10014==    by 0x401890: main (nvme.c:3825)
==10014==
==10014== LEAK SUMMARY:
==10014==    definitely lost: 16 bytes in 1 blocks
==10014==    indirectly lost: 0 bytes in 0 blocks
==10014==      possibly lost: 0 bytes in 0 blocks
==10014==    still reachable: 0 bytes in 0 blocks
==10014==         suppressed: 0 bytes in 0 blocks
==10014==
==10014== 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 bb0f77f731ef1fd3bb3cc2f7f91dbc702a978269..38bf2c53145d9fa1bbfdf2a4670c9b878422b7bb 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3536,7 +3536,7 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin
                         cfg.data_len, dw12, buf, &result);
         if (err < 0) {
                 perror("dir-receive");
-                return errno;
+               goto free;
         }
 
         if (!err) {
@@ -3556,6 +3556,7 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin
         else if (err > 0)
                 fprintf(stderr, "NVMe Status:%s(%x)\n",
                                 nvme_status_to_string(err), err);
+free:
         if (buf)
                 free(buf);
         return err;