]> git.proxmox.com Git - qemu.git/commitdiff
blockdev: Plug memory leak in drive_init() error paths
authorMarkus Armbruster <armbru@redhat.com>
Tue, 8 Feb 2011 14:12:39 +0000 (15:12 +0100)
committerKevin Wolf <kwolf@redhat.com>
Thu, 10 Feb 2011 12:24:28 +0000 (13:24 +0100)
Should have spotted this when doing commit 319ae529.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
blockdev.c

index 24d765806b4f628b16b217420fa2282a3de246eb..0690cc8bea5b2ac1ad4427a6c042ea00864ec341 100644 (file)
@@ -526,7 +526,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
     } else if (ro == 1) {
         if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && type != IF_NONE) {
             error_report("readonly not supported by this bus type");
-            return NULL;
+            goto err;
         }
     }
 
@@ -536,12 +536,19 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
     if (ret < 0) {
         error_report("could not open disk image %s: %s",
                      file, strerror(-ret));
-        return NULL;
+        goto err;
     }
 
     if (bdrv_key_required(dinfo->bdrv))
         autostart = 0;
     return dinfo;
+
+err:
+    bdrv_delete(dinfo->bdrv);
+    qemu_free(dinfo->id);
+    QTAILQ_REMOVE(&drives, dinfo, next);
+    qemu_free(dinfo);
+    return NULL;
 }
 
 void do_commit(Monitor *mon, const QDict *qdict)