From: Markus Armbruster Date: Tue, 8 Feb 2011 14:12:39 +0000 (+0100) Subject: blockdev: Plug memory leak in drive_init() error paths X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1405^2~17^2~2791^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9ae2bffea62ce5158be7475fe41e5fba6d026c1;p=sdk%2Femulator%2Fqemu.git blockdev: Plug memory leak in drive_init() error paths Should have spotted this when doing commit 319ae529. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- 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)