@@ -467,7 +467,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
}
if (!file || !*file) {
*fatal_error = 0;
- return NULL;
+ goto error;
}
if (snapshot) {
/* always use cache=unsafe with snapshot */
@@ -481,7 +481,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
} else if (ro == 1) {
if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && type != IF_NONE) {
fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n");
- return NULL;
+ goto error;
}
}
@@ -491,13 +491,16 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
if (ret < 0) {
fprintf(stderr, "qemu: could not open disk image %s: %s\n",
file, strerror(-ret));
- return NULL;
+ goto error;
}
if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
*fatal_error = 0;
return dinfo;
+error:
+ drive_uninit(dinfo);
+ return NULL;
}
void do_commit(Monitor *mon, const QDict *qdict)
Signed-off-by: Juan Quintela <quintela@redhat.com> --- blockdev.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)