* [PATCH v2 0/2] e2fsprogs: fix memory leaks detected by ASAN
@ 2025-11-21 3:36 Wu Guanghao
2025-11-21 3:36 ` [PATCH v2 1/2] fsck: fix memory leak of inst->type Wu Guanghao
2025-11-21 3:36 ` [PATCH v2 2/2] resize: fix memory leak when exiting normally Wu Guanghao
0 siblings, 2 replies; 5+ messages in thread
From: Wu Guanghao @ 2025-11-21 3:36 UTC (permalink / raw)
To: tytso, linux-ext4, adilger.kernel; +Cc: djwong, yangyun50, wuguanghao3
v1 -> v2:
- Check the return value of ext2fs_close_free()
Wu Guanghao (2):
fsck: fix memory leak of inst->type
resize: fix memory leak when exiting normally
misc/fsck.c | 1 +
resize/main.c | 2 ++
2 files changed, 3 insertions(+)
--
2.27.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] fsck: fix memory leak of inst->type
2025-11-21 3:36 [PATCH v2 0/2] e2fsprogs: fix memory leaks detected by ASAN Wu Guanghao
@ 2025-11-21 3:36 ` Wu Guanghao
2025-11-21 16:23 ` Darrick J. Wong
2025-11-21 3:36 ` [PATCH v2 2/2] resize: fix memory leak when exiting normally Wu Guanghao
1 sibling, 1 reply; 5+ messages in thread
From: Wu Guanghao @ 2025-11-21 3:36 UTC (permalink / raw)
To: tytso, linux-ext4, adilger.kernel; +Cc: djwong, yangyun50, wuguanghao3
The function free_instance() does not release i->type, resulting in a
memory leak.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
misc/fsck.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/misc/fsck.c b/misc/fsck.c
index 64d0e7c0..a06f2668 100644
--- a/misc/fsck.c
+++ b/misc/fsck.c
@@ -235,6 +235,7 @@ static void parse_escape(char *word)
static void free_instance(struct fsck_instance *i)
{
free(i->prog);
+ free(i->type);
free(i->device);
free(i->base_device);
free(i);
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/2] fsck: fix memory leak of inst->type
2025-11-21 3:36 ` [PATCH v2 1/2] fsck: fix memory leak of inst->type Wu Guanghao
@ 2025-11-21 16:23 ` Darrick J. Wong
0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2025-11-21 16:23 UTC (permalink / raw)
To: Wu Guanghao; +Cc: tytso, linux-ext4, adilger.kernel, yangyun50
On Fri, Nov 21, 2025 at 11:36:11AM +0800, Wu Guanghao wrote:
> The function free_instance() does not release i->type, resulting in a
> memory leak.
>
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Looks good!
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> misc/fsck.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/misc/fsck.c b/misc/fsck.c
> index 64d0e7c0..a06f2668 100644
> --- a/misc/fsck.c
> +++ b/misc/fsck.c
> @@ -235,6 +235,7 @@ static void parse_escape(char *word)
> static void free_instance(struct fsck_instance *i)
> {
> free(i->prog);
> + free(i->type);
> free(i->device);
> free(i->base_device);
> free(i);
> --
> 2.27.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] resize: fix memory leak when exiting normally
2025-11-21 3:36 [PATCH v2 0/2] e2fsprogs: fix memory leaks detected by ASAN Wu Guanghao
2025-11-21 3:36 ` [PATCH v2 1/2] fsck: fix memory leak of inst->type Wu Guanghao
@ 2025-11-21 3:36 ` Wu Guanghao
2026-03-05 17:38 ` Theodore Tso
1 sibling, 1 reply; 5+ messages in thread
From: Wu Guanghao @ 2025-11-21 3:36 UTC (permalink / raw)
To: tytso, linux-ext4, adilger.kernel; +Cc: djwong, yangyun50, wuguanghao3
The main() function only releases fs when it exits through the errout or
success_exit labels. When completes normally, it does not release fs.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
resize/main.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/resize/main.c b/resize/main.c
index 08a4bbaf..e7940307 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -702,6 +702,14 @@ int main (int argc, char ** argv)
}
if (fd > 0)
close(fd);
+
+ retval = ext2fs_close_free(&fs);
+ if (retval) {
+ com_err(program_name, retval,
+ _("ext2fs_close"));
+ exit(1);
+ }
+
remove_error_table(&et_ext2_error_table);
return 0;
errout:
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 2/2] resize: fix memory leak when exiting normally
2025-11-21 3:36 ` [PATCH v2 2/2] resize: fix memory leak when exiting normally Wu Guanghao
@ 2026-03-05 17:38 ` Theodore Tso
0 siblings, 0 replies; 5+ messages in thread
From: Theodore Tso @ 2026-03-05 17:38 UTC (permalink / raw)
To: Wu Guanghao; +Cc: linux-ext4, adilger.kernel, djwong, yangyun50
On Fri, Nov 21, 2025 at 11:36:12AM +0800, Wu Guanghao wrote:
> The main() function only releases fs when it exits through the errout or
> success_exit labels. When completes normally, it does not release fs.
>
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
I'm guessing you only tested the online resize code path?
if (mount_flags & EXT2_MF_MOUNTED) {
retval = online_resize_fs(fs, mtpt, &new_size, flags);
} else {
...
retval = resize_fs(fs, &new_size, flags,
((flags & RESIZE_PERCENT_COMPLETE) ?
resize_progress_func : 0));
}
The reason why I ask this is that resize_fs() frees fs on the success path:
rfs->old_fs = fs;
...
ext2fs_free(rfs->old_fs);
... although if we return when an error, we do *not* free ext2fs_free(rfs->old_fs).
So if you were to test with this applied when resizing a non-mounted
file system, I believe you'd get a double free failure.
Cheers,
- Ted
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-05 17:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-21 3:36 [PATCH v2 0/2] e2fsprogs: fix memory leaks detected by ASAN Wu Guanghao
2025-11-21 3:36 ` [PATCH v2 1/2] fsck: fix memory leak of inst->type Wu Guanghao
2025-11-21 16:23 ` Darrick J. Wong
2025-11-21 3:36 ` [PATCH v2 2/2] resize: fix memory leak when exiting normally Wu Guanghao
2026-03-05 17:38 ` Theodore Tso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox