50 lines
1.6 KiB
Diff
50 lines
1.6 KiB
Diff
From fa8544b4229e19679db070c31969c9739f702fd0 Mon Sep 17 00:00:00 2001
|
|
From: Li Jinlin <lijinlin3@huawei.com>
|
|
Date: Tue, 29 Mar 2022 11:07:33 +0800
|
|
Subject: [PATCH 4/6] fat_op_context_new: free ctx->remap and goto correct
|
|
label to avoid memleak
|
|
|
|
When calc_deltas returns an error, need to release ctx->remap,
|
|
and eed to jump to the correct label to release ctx, otherwise
|
|
there will be memory leaks
|
|
|
|
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
|
|
Signed-off-by: Li Jinlin <lijinlin3@huawei.com>
|
|
---
|
|
libparted/fs/r/fat/context.c | 8 +++++---
|
|
1 file changed, 5 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/libparted/fs/r/fat/context.c b/libparted/fs/r/fat/context.c
|
|
index 5ca154c..fce77af 100644
|
|
--- a/libparted/fs/r/fat/context.c
|
|
+++ b/libparted/fs/r/fat/context.c
|
|
@@ -86,9 +86,9 @@ fat_op_context_new (PedFileSystem* new_fs, PedFileSystem* old_fs)
|
|
ctx->frag_sectors = PED_MIN (old_fs_info->cluster_sectors,
|
|
new_fs_info->cluster_sectors);
|
|
if (!fat_set_frag_sectors (new_fs, ctx->frag_sectors))
|
|
- goto error;
|
|
+ goto error_free_ctx;
|
|
if (!fat_set_frag_sectors (old_fs, ctx->frag_sectors))
|
|
- goto error;
|
|
+ goto error_free_ctx;
|
|
|
|
ctx->buffer_frags = old_fs_info->buffer_sectors / ctx->frag_sectors;
|
|
ctx->buffer_map = (FatFragment*) ped_malloc (sizeof (FatFragment)
|
|
@@ -104,10 +104,12 @@ fat_op_context_new (PedFileSystem* new_fs, PedFileSystem* old_fs)
|
|
ctx->new_fs = new_fs;
|
|
ctx->old_fs = old_fs;
|
|
if (!calc_deltas (ctx))
|
|
- goto error_free_buffer_map;
|
|
+ goto error_free_remap;
|
|
|
|
return ctx;
|
|
|
|
+error_free_remap:
|
|
+ free(ctx->remap);
|
|
error_free_buffer_map:
|
|
free (ctx->buffer_map);
|
|
error_free_ctx:
|
|
--
|
|
2.27.0
|
|
|