9ae3a8
From 66e996f40abbca9c62a262beeefb93b7b4c6e64f Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Sat, 8 Feb 2014 09:53:22 +0100
9ae3a8
Subject: [PATCH 32/37] blkdebug: Don't leak bs->file on failure
9ae3a8
9ae3a8
Message-id: <1392117622-28812-33-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 57197
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 32/37] blkdebug: Don't leak bs->file on failure
9ae3a8
Bugzilla: 748906
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
Reported-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	block/blkdebug.c
9ae3a8
9ae3a8
Conflicts because RHEL 7 doesn't have the blockdev-add support
9ae3a8
series for blkdebug.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block/blkdebug.c | 16 ++++++++++------
9ae3a8
 1 file changed, 10 insertions(+), 6 deletions(-)
9ae3a8
---
9ae3a8
 block/blkdebug.c |   16 ++++++++++------
9ae3a8
 1 files changed, 10 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/blkdebug.c b/block/blkdebug.c
9ae3a8
index ccb562b..1e772a5 100644
9ae3a8
--- a/block/blkdebug.c
9ae3a8
+++ b/block/blkdebug.c
9ae3a8
@@ -367,7 +367,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     if (error_is_set(&local_err)) {
9ae3a8
         error_propagate(errp, local_err);
9ae3a8
         ret = -EINVAL;
9ae3a8
-        goto fail;
9ae3a8
+        goto out;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Read rules from config file */
9ae3a8
@@ -376,7 +376,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
         ret = read_config(s, config);
9ae3a8
         if (ret < 0) {
9ae3a8
             error_setg_errno(errp, -ret, "Could not read blkdebug config file");
9ae3a8
-            goto fail;
9ae3a8
+            goto out;
9ae3a8
         }
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -388,13 +388,13 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     if (filename == NULL) {
9ae3a8
         error_setg(errp, "Could not retrieve image file name");
9ae3a8
         ret = -EINVAL;
9ae3a8
-        goto fail;
9ae3a8
+        goto out;
9ae3a8
     }
9ae3a8
 
9ae3a8
     ret = bdrv_file_open(&bs->file, filename, NULL, flags, &local_err);
9ae3a8
     if (ret < 0) {
9ae3a8
         error_propagate(errp, local_err);
9ae3a8
-        goto fail;
9ae3a8
+        goto out;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Set request alignment */
9ae3a8
@@ -404,11 +404,15 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     } else {
9ae3a8
         error_setg(errp, "Invalid alignment");
9ae3a8
         ret = -EINVAL;
9ae3a8
-        goto fail;
9ae3a8
+        goto fail_unref;
9ae3a8
     }
9ae3a8
 
9ae3a8
     ret = 0;
9ae3a8
-fail:
9ae3a8
+    goto out;
9ae3a8
+
9ae3a8
+fail_unref:
9ae3a8
+    bdrv_unref(bs->file);
9ae3a8
+out:
9ae3a8
     qemu_opts_del(opts);
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8