Fix memory leak for _sec_buf_.
==9303== HEAP SUMMARY:
==9303== in use at exit: 0 bytes in 1 blocks
==9303== total heap usage: 31 allocs, 30 frees, 3,915 bytes allocated
==9303==
==9303== Searching for pointers to 1 not-freed blocks
==9303== Checked 70,664 bytes
==9303==
==9303== 0 bytes in 1 blocks are definitely lost in loss record 1 of 1
==9303== at 0x4C2FFC6: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9303== by 0x4C300D1: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9303== by 0x405A4C: sec_send (nvme.c:2415)
==9303== by 0x419527: handle_plugin (plugin.c:150)
==9303== by 0x401890: main (nvme.c:3812)
==9303==
==9303== LEAK SUMMARY:
==9303== definitely lost: 0 bytes in 1 blocks
==9303== indirectly lost: 0 bytes in 0 blocks
==9303== possibly lost: 0 bytes in 0 blocks
==9303== still reachable: 0 bytes in 0 blocks
==9303== suppressed: 0 bytes in 0 blocks
==9303==
==9303== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
if (read(sec_fd, sec_buf, sec_size) < 0) {
fprintf(stderr, "Failed to read data from security file with %s\n",
strerror(errno));
- return EINVAL;
+ err = EINVAL;
+ goto free;
}
err = nvme_sec_send(fd, cfg.namespace_id, cfg.nssf, cfg.spsp, cfg.secp,
fprintf(stderr, "NVME Security Send Command Error:%d\n", err);
else
printf("NVME Security Send Command Success:%d\n", result);
+
+free:
+ free(sec_buf);
return err;
}