Patchwork qemu-io: delete bs instead of leaking it

login
register
mail settings
Submitter Stefan Hajnoczi
Date Oct. 27, 2011, 7:42 a.m.
Message ID <1319701333-5700-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/122082/
State New
Headers show

Comments

Stefan Hajnoczi - Oct. 27, 2011, 7:42 a.m.
Using bdrv_close() is not enough to free a BlockDriverState.  Since we
explicitly create it with bdrv_new(), use bdrv_delete() to close and
delete it.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 qemu-io.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Kevin Wolf - Oct. 27, 2011, 8:47 a.m.
Am 27.10.2011 09:42, schrieb Stefan Hajnoczi:
> Using bdrv_close() is not enough to free a BlockDriverState.  Since we
> explicitly create it with bdrv_new(), use bdrv_delete() to close and
> delete it.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

At the end of main() there's another bdrv_close() call that should be
changed.

Kevin

Patch

diff --git a/qemu-io.c b/qemu-io.c
index e91af37..e8ac704 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1581,7 +1581,7 @@  static const cmdinfo_t map_cmd = {
 
 static int close_f(int argc, char **argv)
 {
-    bdrv_close(bs);
+    bdrv_delete(bs);
     bs = NULL;
     return 0;
 }
@@ -1610,6 +1610,7 @@  static int openfile(char *name, int flags, int growable)
 
         if (bdrv_open(bs, name, flags, NULL) < 0) {
             fprintf(stderr, "%s: can't open device %s\n", progname, name);
+            bdrv_delete(bs);
             bs = NULL;
             return 1;
         }