summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2011-02-08 15:12:39 +0100
committerJustin M. Forbes <jforbes@redhat.com>2011-02-08 08:41:54 -0600
commit0893194783a006380b8b7cf0c0d79041bd4da93f (patch)
tree699438ccd58dec6b931984fe05dc7c5e263894fd
parente5f1c19665b3cf7ff33431c1c8c898177504dcd5 (diff)
blockdev: Plug memory leak in drive_init() error paths
Should have spotted this when doing commit 319ae529. Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r--blockdev.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/blockdev.c b/blockdev.c
index 24d765806b..0690cc8bea 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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)