Skip to contentSkip to conversation

vdi: Fix memory leak

PATCH In review Kevin Wolf 2 participants 3 messages Nov 22, 2011 – Nov 23, 2011 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 vdi: Fix memory leak

The block map is allocated in vdi_open, but was never freed.

---
Applies on top if the migration blocker series.

 block/vdi.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
block/vdi.c +3 -0
index 7dda522..02da6b4 100644
@@ -949,6 +949,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
 static void vdi_close(BlockDriverState *bs)
 {
     BDRVVdiState *s = bs->opaque;
+
+    g_free(s->bmap);
+
     migrate_del_blocker(s->migration_blocker);
     error_free(s->migration_blocker);
 }
Signature · 1 line
1.7.6.4
Reviewed-by on v1 1/1
#1 lore raw

Am 22.11.2011 17:16, schrieb Kevin Wolf:

Quoted 14 lines

The block map is allocated in vdi_open, but was never freed.

---
Applies on top if the migration blocker series.

  block/vdi.c |    3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)
block/vdi.c +0 -0
index 7dda522..02da6b4 100644

block/vdi.c static int vdi_create(const char *filename, QEMUOptionParameter *options) · line 957

Quoted 9 lines
block/vdi.c +3 -0
@@ -949,6 +949,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
  static void vdi_close(BlockDriverState *bs)
  {
      BDRVVdiState *s = bs->opaque;
+
+    g_free(s->bmap);
+
      migrate_del_blocker(s->migration_blocker);
      error_free(s->migration_blocker);
  }

If vdi_close is called after a jump to label fail_free_bmap, g_free(s->bmap) will be called twice.

Setting s->bmap = NULL after g_free in fail_free_bmap would be safer.

Otherwise your patch is fine. If you send an update, you can add

Regards,
Stefan Weil

author
#2 lore raw

Am 22.11.2011 19:37, schrieb Stefan Weil:

Quoted 19 lines

Am 22.11.2011 17:16, schrieb Kevin Wolf:

Quoted 18 lines

The block map is allocated in vdi_open, but was never freed.

---
Applies on top if the migration blocker series.

  block/vdi.c |    3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)
block/vdi.c +1 -0
index 7dda522..02da6b4 100644
@@ -949,6 +949,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
  static void vdi_close(BlockDriverState *bs)
  {
      BDRVVdiState *s = bs->opaque;
+
Quoted 8 lines

block/vdi.c static int vdi_create(const char *filename, QEMUOptionParameter *options) · line 957

Quoted 5 lines
block/vdi.c +2 -0
+    g_free(s->bmap);
+
      migrate_del_blocker(s->migration_blocker);
      error_free(s->migration_blocker);
  }

If vdi_close is called after a jump to label fail_free_bmap, g_free(s->bmap) will be called twice.

bdrv_close() may only ever be called on a successfully opened image.

In fact, block.c already ensures this. The BDRVVdiState would already be freed in the failing bdrv_open_common() and bs->drv would be set to NULL, so that an invalid bdrv_close() would end up doing nothing.

Quoted 7 lines

Setting s->bmap = NULL after g_free in fail_free_bmap would be safer.

Otherwise your patch is fine. If you send an update, you can add

Thanks.

Kevin