From: Kevin Wolf Date: Fri, 10 Sep 2010 10:27:03 +0000 (+0200) Subject: vvfat: Fix double free for opening the image rw X-Git-Tag: v0.13.0-rc3^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=345a6d2b54f0c3705a088e626d24e9376ff4f233;p=thirdparty%2Fqemu.git vvfat: Fix double free for opening the image rw Allocation and deallocation of bs->opaque is not in the control of a block driver. Therefore it should not set bs->opaque to a data structure used by another bs, or closing the image will lead to a double free. Signed-off-by: Kevin Wolf (cherry picked from commit 0af1e52e93bf5da63b15f1f9596dd4c076da07dc) --- diff --git a/block/vvfat.c b/block/vvfat.c index 5898d664b04..07720371c9f 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2768,12 +2768,12 @@ static int vvfat_is_allocated(BlockDriverState *bs, static int write_target_commit(BlockDriverState *bs, int64_t sector_num, const uint8_t* buffer, int nb_sectors) { - BDRVVVFATState* s = bs->opaque; + BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque); return try_commit(s); } static void write_target_close(BlockDriverState *bs) { - BDRVVVFATState* s = bs->opaque; + BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque); bdrv_delete(s->qcow); free(s->qcow_filename); } @@ -2816,7 +2816,8 @@ static int enable_write_target(BDRVVVFATState *s) s->bs->backing_hd = calloc(sizeof(BlockDriverState), 1); s->bs->backing_hd->drv = &vvfat_write_target; - s->bs->backing_hd->opaque = s; + s->bs->backing_hd->opaque = qemu_malloc(sizeof(void*)); + *(void**)s->bs->backing_hd->opaque = s; return 0; }