From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 2/4] xen_disk: Plug memory leak on error path
Date: Mon, 8 Sep 2014 18:50:59 +0200 [thread overview]
Message-ID: <1410195061-8267-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1410195061-8267-1-git-send-email-armbru@redhat.com>
While there, streamline control flow a bit.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/block/xen_disk.c | 31 ++++++++++++++-----------------
1 file 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");
--
1.9.3
next prev parent reply other threads:[~2014-09-08 16:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-08 16:50 [Qemu-devel] [PATCH 0/4] Block-related miscellaneous cleanups Markus Armbruster
2014-09-08 16:50 ` [Qemu-devel] [PATCH 1/4] qemu-io: Clean up openfile() after commit 2e40134 Markus Armbruster
2014-09-08 16:50 ` Markus Armbruster [this message]
2014-09-08 16:51 ` [Qemu-devel] [PATCH 3/4] xen: Drop redundant bdrv_close() from pci_piix3_xen_ide_unplug() Markus Armbruster
2014-09-08 16:51 ` [Qemu-devel] [PATCH 4/4] thread-pool: Drop unnecessary includes Markus Armbruster
2014-09-09 8:53 ` [Qemu-devel] [PATCH 0/4] Block-related miscellaneous cleanups Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410195061-8267-3-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).