[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] block vvfat.c fix leak when failure occurs
From: |
Daniella Lee |
Subject: |
[PATCH] block vvfat.c fix leak when failure occurs |
Date: |
Fri, 19 Nov 2021 19:25:53 +0800 |
Based on your suggestions. I made a new patch which contians:
1.format detection
2.replace calloc with g_malloc0 in enable_write_target function
3.use g_free without null pointer detection in vvfat_open function
4.delete line "ret = 0", use return ret directly in vvfat_open function
Signed-off-by: Daniella Lee <daniellalee111@gmail.com>
---
block/vvfat.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index 05e78e3c27..5dacc6cfac 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1279,8 +1279,18 @@ static int vvfat_open(BlockDriverState *bs, QDict
*options, int flags,
qemu_co_mutex_init(&s->lock);
- ret = 0;
+ qemu_opts_del(opts);
+
+ return 0;
+
fail:
+ g_free(s->qcow_filename);
+ s->qcow_filename = NULL;
+ g_free(s->cluster_buffer);
+ s->cluster_buffer = NULL;
+ g_free(s->used_clusters);
+ s->used_clusters = NULL;
+
qemu_opts_del(opts);
return ret;
}
@@ -3118,7 +3128,7 @@ static int enable_write_target(BlockDriverState *bs,
Error **errp)
int size = sector2cluster(s, s->sector_count);
QDict *options;
- s->used_clusters = calloc(size, 1);
+ s->used_clusters = g_malloc0(size);
array_init(&(s->commits), sizeof(commit_t));
@@ -3166,8 +3176,6 @@ static int enable_write_target(BlockDriverState *bs,
Error **errp)
return 0;
err:
- g_free(s->qcow_filename);
- s->qcow_filename = NULL;
return ret;
}
--
2.17.1