aboutsummaryrefslogtreecommitdiff
path: root/hw/block
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-09-08 18:50:59 +0200
committerKevin Wolf <kwolf@redhat.com>2014-09-10 10:41:29 +0200
commitcedccf1381c2fd6592d6322f3cd9cc6bf6621967 (patch)
tree1d338aa43a2c81811472517b10e0ab20c31cd43e /hw/block
parentdbb651c46cc1d30497763f3bc0229206f7522c44 (diff)
downloadqemu-cedccf1381c2fd6592d6322f3cd9cc6bf6621967.zip
qemu-cedccf1381c2fd6592d6322f3cd9cc6bf6621967.tar.gz
qemu-cedccf1381c2fd6592d6322f3cd9cc6bf6621967.tar.bz2
xen_disk: Plug memory leak on error path
The Error object was leaked after failed bdrv_new(). While there, streamline control flow a bit. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw/block')
-rw-r--r--hw/block/xen_disk.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index a221d0b..2dcef07 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -852,28 +852,25 @@ static int blk_connect(struct XenDevice *xendev)
blkdev->dinfo = drive_get(IF_XEN, 0, index);
if (!blkdev->dinfo) {
Error *local_err = NULL;
+ BlockDriver *drv;
+
/* setup via xenbus -> create new block driver instance */
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
- blkdev->bs = bdrv_new(blkdev->dev, &local_err);
- if (local_err) {
- blkdev->bs = NULL;
- }
- if (blkdev->bs) {
- BlockDriver *drv = bdrv_find_whitelisted_format(blkdev->fileproto,
- readonly);
- if (bdrv_open(&blkdev->bs, blkdev->filename, NULL, NULL, qflags,
- drv, &local_err) != 0)
- {
- xen_be_printf(&blkdev->xendev, 0, "error: %s\n",
- error_get_pretty(local_err));
- error_free(local_err);
- bdrv_unref(blkdev->bs);
- blkdev->bs = NULL;
- }
- }
+ blkdev->bs = bdrv_new(blkdev->dev, NULL);
if (!blkdev->bs) {
return -1;
}
+
+ drv = bdrv_find_whitelisted_format(blkdev->fileproto, readonly);
+ if (bdrv_open(&blkdev->bs, blkdev->filename, NULL, NULL, qflags,
+ drv, &local_err) != 0) {
+ xen_be_printf(&blkdev->xendev, 0, "error: %s\n",
+ error_get_pretty(local_err));
+ error_free(local_err);
+ bdrv_unref(blkdev->bs);
+ blkdev->bs = NULL;
+ return -1;
+ }
} else {
/* setup via qemu cmdline -> already setup for us */
xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");