From: Wang Shilong <wshilong@xxxxxxx> valgrind detected few memory leaks: 1) quota context is not released after merging. 2) three block bufs are not freed in read_bitmaps_range_start() 3) @refcount_orig should be released Signed-off-by: Wang Shilong <wshilong@xxxxxxx> Signed-off-by: Saranya Muruganandam <saranyamohan@xxxxxxxxxx> --- e2fsck/e2fsck.c | 4 ++++ e2fsck/pass1.c | 1 + lib/ext2fs/rw_bitmaps.c | 14 ++++---------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/e2fsck/e2fsck.c b/e2fsck/e2fsck.c index a03550c0..e406f6dd 100644 --- a/e2fsck/e2fsck.c +++ b/e2fsck/e2fsck.c @@ -102,6 +102,10 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx) ea_refcount_free(ctx->refcount_extra); ctx->refcount_extra = 0; } + if (ctx->refcount_orig) { + ea_refcount_free(ctx->refcount_orig); + ctx->refcount_orig = 0; + } if (ctx->ea_block_quota_blocks) { ea_refcount_free(ctx->ea_block_quota_blocks); ctx->ea_block_quota_blocks = 0; diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 70826866..7768119b 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -3113,6 +3113,7 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx) fclose(thread_ctx->problem_logf); } + quota_release_context(&thread_ctx->qctx); /* * @block_metadata_map and @block_dup_map are * shared, so we don't free them. diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index eb791202..5fde2632 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -269,7 +269,7 @@ static errcode_t read_bitmaps_range_start(ext2_filsys fs, int do_inode, int do_b dgrp_t i; char *block_bitmap = 0, *inode_bitmap = 0; char *buf; - errcode_t retval; + errcode_t retval = 0; int block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; int tail_flags = 0; @@ -432,18 +432,12 @@ static errcode_t read_bitmaps_range_start(ext2_filsys fs, int do_inode, int do_b success_cleanup: if (start == 0 && end == fs->group_desc_count - 1) { - if (inode_bitmap) { - ext2fs_free_mem(&inode_bitmap); + if (inode_bitmap) fs->flags &= ~EXT2_FLAG_IBITMAP_TAIL_PROBLEM; - } - if (block_bitmap) { - ext2fs_free_mem(&block_bitmap); + if (block_bitmap) fs->flags &= ~EXT2_FLAG_BBITMAP_TAIL_PROBLEM; - } } fs->flags |= tail_flags; - return 0; - cleanup: if (inode_bitmap) ext2fs_free_mem(&inode_bitmap); @@ -451,8 +445,8 @@ cleanup: ext2fs_free_mem(&block_bitmap); if (buf) ext2fs_free_mem(&buf); - return retval; + return retval; } static errcode_t read_bitmaps_range_end(ext2_filsys fs, int do_inode, int do_block, -- 2.29.2.299.gdc1121823c-goog