From cedccf1381c2fd6592d6322f3cd9cc6bf6621967 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 8 Sep 2014 18:50:59 +0200 Subject: 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 Signed-off-by: Kevin Wolf --- hw/block/xen_disk.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'hw') diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index a221d0bfca..2dcef07793 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"); -- cgit v1.2.3