diff mbox series

[RFCv1,62/72] e2fsck: fix memory leaks with pfsck enabled

Message ID 1a72168b983a877458d5fc20409620df31b6a619.1667822612.git.ritesh.list@gmail.com
State Under Review
Delegated to: Theodore Ts'o
Headers show
Series e2fsprogs: Parallel fsck support | expand

Commit Message

Ritesh Harjani (IBM) Nov. 7, 2022, 12:21 p.m. UTC
From: Wang Shilong <wshilong@ddn.com>

valgrind detected two memory leaks:

1) quota context is not released after merging.
2) @refcount_orig should be released

Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
 e2fsck/e2fsck.c | 4 ++++
 e2fsck/pass1.c  | 1 +
 2 files changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/e2fsck/e2fsck.c b/e2fsck/e2fsck.c
index 53af8905..db0a5059 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 ed4275c3..d745699d 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -3039,6 +3039,7 @@  static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx)
 
 	retval = e2fsck_pass1_merge_context(global_ctx, thread_ctx);
 
+	quota_release_context(&thread_ctx->qctx);
 	/*
 	 * @block_metadata_map and @block_dup_map are
 	 * shared, so we don't free them.