]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block: Do not unref bs->file on error in BD's open
authorMax Reitz <mreitz@redhat.com>
Thu, 13 Apr 2017 15:43:34 +0000 (17:43 +0200)
committerKevin Wolf <kwolf@redhat.com>
Thu, 27 Apr 2017 14:12:13 +0000 (16:12 +0200)
The block layer takes care of removing the bs->file child if the block
driver's bdrv_open()/bdrv_file_open() implementation fails. The block
driver therefore does not need to do so, and indeed should not unless it
sets bs->file to NULL afterwards -- because if this is not done, the
bdrv_unref_child() in bdrv_open_inherit() will dereference the freed
memory block at bs->file afterwards, which is not good.

We can now decide whether to add a "bs->file = NULL;" after each of the
offending bdrv_unref_child() invocations, or just drop them altogether.
The latter is simpler, so let's do that.

Cc: qemu-stable <qemu-stable@nongnu.org>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/blkdebug.c
block/blkreplay.c
block/blkverify.c

index 67e8024e36db9dbae51ec4a1711c4aeac759e833..cc4a146e847974a8fcf9f4200e75e79f989ff356 100644 (file)
@@ -389,14 +389,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
     } else if (align) {
         error_setg(errp, "Invalid alignment");
         ret = -EINVAL;
-        goto fail_unref;
+        goto out;
     }
 
     ret = 0;
     goto out;
 
-fail_unref:
-    bdrv_unref_child(bs, bs->file);
 out:
     if (ret < 0) {
         g_free(s->config_file);
index e1102119fbeafc4d72fbca0cd1a1b029372ffb03..6aa5fd4156e61b8e718b47ad741c9889e10cdcf2 100755 (executable)
@@ -37,9 +37,6 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
 
     ret = 0;
 fail:
-    if (ret < 0) {
-        bdrv_unref_child(bs, bs->file);
-    }
     return ret;
 }
 
index 9a1e21c6ad3723375fa97a9ba0225e956732a31f..af23281669e979b5d2ddc740676c81235d7d125a 100644 (file)
@@ -142,9 +142,6 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
 
     ret = 0;
 fail:
-    if (ret < 0) {
-        bdrv_unref_child(bs, bs->file);
-    }
     qemu_opts_del(opts);
     return ret;
 }