Fix memory leak for _buf_.
==9566== HEAP SUMMARY:
==9566== in use at exit: 1,024 bytes in 1 blocks
==9566== total heap usage: 52 allocs, 51 frees, 16,681 bytes allocated
==9566==
==9566== Searching for pointers to 1 not-freed blocks
==9566== Checked 70,656 bytes
==9566==
==9566== 1,024 bytes in 1 blocks are definitely lost in loss record 1 of
1
==9566== at 0x4C2FFC6: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9566== by 0x4C300D1: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9566== by 0x402174: dir_send (nvme.c:2535)
==9566== by 0x419317: handle_plugin (plugin.c:150)
==9566== by 0x401890: main (nvme.c:3818)
==9566==
==9566== LEAK SUMMARY:
==9566== definitely lost: 1,024 bytes in 1 blocks
==9566== indirectly lost: 0 bytes in 0 blocks
==9566== possibly lost: 0 bytes in 0 blocks
==9566== still reachable: 0 bytes in 0 blocks
==9566== suppressed: 0 bytes in 0 blocks
==9566==
==9566== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
ffd = open(cfg.file, O_RDONLY);
if (ffd <= 0) {
fprintf(stderr, "no firmware file provided\n");
- return -EINVAL;
+ err = EINVAL;
+ goto free;
}
}
if (read(ffd, (void *)buf, cfg.data_len) < 0) {
fprintf(stderr, "failed to read data buffer from input file\n");
- return EINVAL;
+ err = EINVAL;
+ goto free;
}
}
cfg.data_len, dw12, buf, &result);
if (err < 0) {
perror("dir-send");
- return errno;
+ goto free;
}
if (!err) {
printf("dir-send: type %#x, operation %#x, spec_val %#x, nsid %#x, result %#x \n",
else if (err > 0)
fprintf(stderr, "NVMe Status:%s(%x)\n",
nvme_status_to_string(err), err);
+
+free:
if (buf)
free(buf);
return err;