Function vvfat_open called function enable_write_target and init_directories,
and these functions malloc new memory for BDRVVVFATState::qcow_filename,
BDRVVVFATState::used_clusters, and BDRVVVFATState::cluster_buff.
When the specified folder does not exist ,it may contains memory leak.
After init_directories function is executed, the vvfat_open return -EIO,
and bdrv_open_driver goto label open_failed,
the program use g_free(bs->opaque) to release BDRVVVFATState struct
without members mentioned.
command line:
qemu-system-x86_64 -hdb <vdisk qcow file> -usb -device usb-storage,drive=fat16
-drive file=fat:rw:fat-type=16:"<path of a host folder does not exist>",
id=fat16,format=raw,if=none
enable_write_target called:
(gdb) bt
#0 enable_write_target (bs=0x555556f9f000, errp=0x7fffffffd780)
at ../block/vvfat.c:3114
#1 vvfat_open (bs=0x555556f9f000, options=0x555556fa45d0,
flags=155650, errp=0x7fffffffd780) at ../block/vvfat.c:1236
#2 bdrv_open_driver (bs=0x555556f9f000, drv=0x555556c47920 <bdrv_vvfat>,
node_name=0x0, options=0x555556fa45d0, open_flags=155650,
errp=0x7fffffffd890) at ../block.c:1558
#3 bdrv_open_common (bs=0x555556f9f000, file=0x0, options=0x555556fa45d0,
errp=0x7fffffffd890) at ../block.c:1852
#4 bdrv_open_inherit (filename=0x555556f73310 "fat:rw:<dirNone>",
reference=0x0, options=0x555556fa45d0, flags=40962, parent=0x555556f98cd0,
child_class=0x555556b1d6a0 <child_of_bds>, child_role=19,
errp=0x7fffffffda90) at ../block.c:3779
#5 bdrv_open_child_bs (filename=0x555556f73310 "fat:rw:<dirNone>",
options=0x555556f9cfc0, bdref_key=0x555556239bb8 "file",
parent=0x555556f98cd0, child_class=0x555556b1d6a0 <child_of_bds>,
child_role=19, allow_none=true, errp=0x7fffffffda90) at ../block.c:3419
#6 bdrv_open_inherit (filename=0x555556f73310 "fat:rw:<dirNone>",
reference=0x0, options=0x555556f9cfc0, flags=8194, parent=0x0,
child_class=0x0, child_role=0, errp=0x555556c98c40 <error_fatal>)
at ../block.c:3726
#7 bdrv_open (filename=0x555556f73310 "fat:rw:<dirNone>", reference=0x0,
options=0x555556f757b0, flags=0, errp=0x555556c98c40 <error_fatal>)
at ../block.c:3872
#8 blk_new_open (filename=0x555556f73310 "fat:rw:<dirNone>", reference=0x0,
options=0x555556f757b0, flags=0, errp=0x555556c98c40 <error_fatal>)
at ../block/block-backend.c:436
#9 blockdev_init (file=0x555556f73310 "fat:rw:<dirNone>",
bs_opts=0x555556f757b0, errp=0x555556c98c40 <error_fatal>)
at ../blockdev.c:608
#10 drive_new (all_opts=0x555556d2b700, block_default_type=IF_IDE,
errp=0x555556c98c40 <error_fatal>) at ../blockdev.c:992
......
Signed-off-by: Daniella Lee <daniellalee111@gmail.com>
---
block/vvfat.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/block/vvfat.c b/block/vvfat.c
index 05e78e3c27..454a74c5d5 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1280,7 +1280,22 @@ static int vvfat_open(BlockDriverState *bs, QDict
*options, int flags,
qemu_co_mutex_init(&s->lock);
ret = 0;
+
+ qemu_opts_del(opts);
+ return ret;