diff options
author | Markus Armbruster <armbru@redhat.com> | 2011-02-08 15:12:39 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-02-10 13:24:28 +0100 |
commit | a9ae2bffea62ce5158be7475fe41e5fba6d026c1 (patch) | |
tree | ef99842a46558254f4cf2759a873e0cfe7f2d130 | |
parent | 2753d4a5fa44d980cc6a279f323a12ca8d172972 (diff) | |
download | qemu-a9ae2bffea62ce5158be7475fe41e5fba6d026c1.zip qemu-a9ae2bffea62ce5158be7475fe41e5fba6d026c1.tar.gz qemu-a9ae2bffea62ce5158be7475fe41e5fba6d026c1.tar.bz2 |
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>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | blockdev.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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) |