]>
Commit | Line | Data |
---|---|---|
e74c0f31 | 1 | From 80a3ed331899e4710b33c4b2a88f1b7b888d6497 Mon Sep 17 00:00:00 2001 |
90a6d957 WB |
2 | From: Max Reitz <mreitz@redhat.com> |
3 | Date: Thu, 13 Apr 2017 17:43:34 +0200 | |
e74c0f31 | 4 | Subject: [PATCH 03/23] block: Do not unref bs->file on error in BD's open |
90a6d957 WB |
5 | |
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. | |
12 | ||
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. | |
16 | ||
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> | |
22 | --- | |
23 | block/blkdebug.c | 4 +--- | |
24 | block/blkreplay.c | 3 --- | |
25 | block/blkverify.c | 3 --- | |
26 | 3 files changed, 1 insertion(+), 9 deletions(-) | |
27 | ||
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, | |
33 | } else if (align) { | |
34 | error_setg(errp, "Invalid alignment"); | |
35 | ret = -EINVAL; | |
36 | - goto fail_unref; | |
37 | + goto out; | |
38 | } | |
39 | ||
40 | ret = 0; | |
41 | goto out; | |
42 | ||
43 | -fail_unref: | |
44 | - bdrv_unref_child(bs, bs->file); | |
45 | out: | |
46 | if (ret < 0) { | |
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, | |
53 | ||
54 | ret = 0; | |
55 | fail: | |
56 | - if (ret < 0) { | |
57 | - bdrv_unref_child(bs, bs->file); | |
58 | - } | |
59 | return ret; | |
60 | } | |
61 | ||
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, | |
67 | ||
68 | ret = 0; | |
69 | fail: | |
70 | - if (ret < 0) { | |
71 | - bdrv_unref_child(bs, bs->file); | |
72 | - } | |
73 | qemu_opts_del(opts); | |
74 | return ret; | |
75 | } | |
76 | -- | |
77 | 2.11.0 | |
78 |