]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/ymtc: fixup resource leaks
authorHannes Reinecke <hare@suse.de>
Fri, 22 Apr 2022 11:14:37 +0000 (13:14 +0200)
committerHannes Reinecke <hare@suse.de>
Fri, 22 Apr 2022 11:14:37 +0000 (13:14 +0200)
Found by coverity.

Signed-off-by: Hannes Reinecke <hare@suse.de>
plugins/ymtc/ymtc-nvme.c

index 5abc1939979c69a214345460c7dd49b832f4121d..7c34798bfc9d0050166965d4cd2bfa677e766497 100644 (file)
@@ -30,9 +30,21 @@ static int show_ymtc_smart_log(int fd, __u32 nsid, const char *devname,
     u8 *nm = malloc(NM_SIZE * sizeof(u8));
     u8 *raw = malloc(RAW_SIZE * sizeof(u8));
 
+    if (!nm) {
+        if (raw)
+            free(raw);
+        return -1;
+    }
+    if (!raw) {
+        free(nm);
+        return -1;
+    }
     err = nvme_identify_ctrl(fd, &ctrl);
-    if (err)
+    if (err) {
+        free(nm);
+        free(raw);
         return err;
+    }
 
     snprintf(fw_ver, sizeof(fw_ver), "%c.%c%c.%c%c%c%c",
         ctrl.fr[0], ctrl.fr[1], ctrl.fr[2], ctrl.fr[3],