]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-cli: fix memory leak in passthru()
authorMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 12:28:56 +0000 (21:28 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 12:28:56 +0000 (21:28 +0900)
If _metadata_ is allocated with metadata_len in fail case of
posix_memalign() for _data_, it should be freed properly.

Add freeing _metadata_ if _data_ is failed to be allocated.

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

diff --git a/nvme.c b/nvme.c
index 38bf2c53145d9fa1bbfdf2a4670c9b878422b7bb..bf9b18d1ef1247f6bddfe89ea28b225fbcc595a1 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3679,6 +3679,8 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
                metadata = malloc(cfg.metadata_len);
        if (cfg.data_len) {
                if (posix_memalign(&data, getpagesize(), cfg.data_len)) {
+                       if (metadata)
+                               free(metadata);
                        fprintf(stderr, "can not allocate data payload\n");
                        return ENOMEM;
                }