]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Fix leak of mbuffer on error exit path
authorColin Ian King <colin.king@canonical.com>
Fri, 3 Jun 2016 18:27:52 +0000 (19:27 +0100)
committerColin Ian King <colin.king@canonical.com>
Fri, 3 Jun 2016 18:27:52 +0000 (19:27 +0100)
building with clang scan-build picked up a memory leak:
nvme.c:2176:3: warning: Potential leak of memory pointed to by 'mbuffer'
   fprintf(stderr, "failed to read data buffer from input file\n");
   ^~~~~~~

instead of returning, jump to free_and_return which performs the
correct cleanup.  Also fix the indentation of the return at the end of
the function.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 6331f83d7017f8fb99cafd0761cd40696f33e150..72a85a43b230adcf0b5183040f86d968ce9fade1 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2174,8 +2174,8 @@ static int submit_io(int opcode, char *command, const char *desc,
 
        if ((opcode & 1) && read(dfd, (void *)buffer, cfg.data_size) < 0) {
                fprintf(stderr, "failed to read data buffer from input file\n");
-               free(buffer);
-               return EINVAL;
+               err = EINVAL;
+               goto free_and_return;
        }
 
        if ((opcode & 1) && cfg.metadata_size &&
@@ -2230,7 +2230,7 @@ static int submit_io(int opcode, char *command, const char *desc,
        free(buffer);
        if (cfg.metadata_size)
                free(mbuffer);
-    return err;
+       return err;
 }
 
 static int compare(int argc, char **argv)