1 From 7abd8d3ceb29140469c3662fb53de6a4dfe4623e Mon Sep 17 00:00:00 2001
2 From: Max Reitz <mreitz@redhat.com>
3 Date: Thu, 13 Apr 2017 17:43:34 +0200
4 Subject: [PATCH 03/15] block: Do not unref bs->file on error in BD's open
6 The block layer takes care of removing the bs->file child if the block
7 driver's bdrv_open()/bdrv_file_open() implementation fails. The block
8 driver therefore does not need to do so, and indeed should not unless it
9 sets bs->file to NULL afterwards -- because if this is not done, the
10 bdrv_unref_child() in bdrv_open_inherit() will dereference the freed
11 memory block at bs->file afterwards, which is not good.
13 We can now decide whether to add a "bs->file = NULL;" after each of the
14 offending bdrv_unref_child() invocations, or just drop them altogether.
15 The latter is simpler, so let's do that.
17 Cc: qemu-stable <qemu-stable@nongnu.org>
18 Signed-off-by: Max Reitz <mreitz@redhat.com>
19 Reviewed-by: Eric Blake <eblake@redhat.com>
20 Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
21 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
23 block/blkdebug.c | 4 +---
24 block/blkreplay.c | 3 ---
25 block/blkverify.c | 3 ---
26 3 files changed, 1 insertion(+), 9 deletions(-)
28 diff --git a/block/blkdebug.c b/block/blkdebug.c
29 index 67e8024e36..cc4a146e84 100644
30 --- a/block/blkdebug.c
31 +++ b/block/blkdebug.c
32 @@ -389,14 +389,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
34 error_setg(errp, "Invalid alignment");
44 - bdrv_unref_child(bs, bs->file);
47 g_free(s->config_file);
48 diff --git a/block/blkreplay.c b/block/blkreplay.c
49 index e1102119fb..6aa5fd4156 100755
50 --- a/block/blkreplay.c
51 +++ b/block/blkreplay.c
52 @@ -37,9 +37,6 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
57 - bdrv_unref_child(bs, bs->file);
62 diff --git a/block/blkverify.c b/block/blkverify.c
63 index 9a1e21c6ad..af23281669 100644
64 --- a/block/blkverify.c
65 +++ b/block/blkverify.c
66 @@ -142,9 +142,6 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
71 - bdrv_unref_child(bs, bs->file);