Patchwork [1/2] block: Set backing_hd to NULL after deleting it

login
register
mail settings
Submitter Stefan Hajnoczi
Date April 17, 2010, 9:49 a.m.
Message ID <1271497747-4463-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/50379/
State New
Headers show

Comments

Stefan Hajnoczi - April 17, 2010, 9:49 a.m.
It is safer to set backing_hd to NULL after deleting it so that any use
after deletion is obvious during development.  Happy segfaulting!

This patch should be applied after Kevin Wolf's "vmdk: Convert to
bdrv_open" so that vmdk does not segfault on close.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Stefan Hajnoczi - April 17, 2010, 10:26 a.m.
On Sat, Apr 17, 2010 at 10:49 AM, Stefan Hajnoczi
<stefanha@linux.vnet.ibm.com> wrote:
> This patch should be applied after Kevin Wolf's "vmdk: Convert to
> bdrv_open" so that vmdk does not segfault on close.

This is a mistake, vmdk will check backing_hd != NULL so it is safe.

Stefan
Kevin Wolf - April 19, 2010, 8:41 a.m.
Am 17.04.2010 11:49, schrieb Stefan Hajnoczi:
> It is safer to set backing_hd to NULL after deleting it so that any use
> after deletion is obvious during development.  Happy segfaulting!
> 
> This patch should be applied after Kevin Wolf's "vmdk: Convert to
> bdrv_open" so that vmdk does not segfault on close.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Series looks good, applied both patches to the block branch.

Kevin

Patch

diff --git a/block.c b/block.c
index 12cf434..e7e74d9 100644
--- a/block.c
+++ b/block.c
@@ -523,8 +523,10 @@  unlink_and_fail:
 void bdrv_close(BlockDriverState *bs)
 {
     if (bs->drv) {
-        if (bs->backing_hd)
+        if (bs->backing_hd) {
             bdrv_delete(bs->backing_hd);
+            bs->backing_hd = NULL;
+        }
         bs->drv->bdrv_close(bs);
         qemu_free(bs->opaque);
 #ifdef _WIN32