Skip to contentSkip to conversation

qcow2: fix new_blocks double-free in alloc_refcount_block()

PATCH New Stefan Hajnoczi 1 participant 1 message Aug 15, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qcow2: fix new_blocks double-free in alloc_refcount_block()

Commit de82815db1c89da058b7fb941dab137d6d9ab738 ("qcow2: Handle failure for potentially large allocations") introduced a double-free of new_blocks in the alloc_refcount_block() error path.

The qemu-iotests qcow2 026 test case was failing because qemu-io segfaulted.

Make sure new_blocks is NULL after we free it the first time.

---
 block/qcow2-refcount.c | 1 +
 1 file changed, 1 insertion(+)
block/qcow2-refcount.c +1 -0
index d60e2fe..3b77470 100644
@@ -381,6 +381,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
     ret = bdrv_pwrite_sync(bs->file, meta_offset, new_blocks,
         blocks_clusters * s->cluster_size);
     g_free(new_blocks);
+    new_blocks = NULL;
     if (ret < 0) {
         goto fail_table;
     }
Signature · 1 line
1.9.3