Patchwork [09/18] block: Set backing_hd to NULL after deleting it

login
register
mail settings
Submitter Kevin Wolf
Date April 30, 2010, 2 p.m.
Message ID <1272636040-17374-10-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/51339/
State New
Headers show

Comments

Kevin Wolf - April 30, 2010, 2 p.m.
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

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>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Patch

diff --git a/block.c b/block.c
index 56835af..b318355 100644
--- a/block.c
+++ b/block.c
@@ -589,8 +589,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