From 8d561b5d93a00d3b227917a0ff25da5fd5d64ffc Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Mon, 28 Sep 2020 10:27:12 +0800 Subject: [PATCH] LU-8465 e2fsck: fix memory leaks with pfsck enabled 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 Change-Id: I13e51c31cacba9ed14bc9f4d4ce82ec0a6cfe610 Reviewed-on: https://review.whamcloud.com/40069 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo --- 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 140caf3..277d9c8 100644 --- a/e2fsck/e2fsck.c +++ b/e2fsck/e2fsck.c @@ -106,6 +106,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 ebcebf9..8c8e0de 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -3387,6 +3387,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 eb79120..5fde263 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, -- 1.8.3.1