* [PATCH 0/2] e2fsprogs: fix memory leaks detected by ASAN
@ 2025-11-18 13:25 Wu Guanghao
2025-11-18 13:26 ` [PATCH 1/2] fsck: fix memory leak of inst->type Wu Guanghao
2025-11-18 13:26 ` [PATCH 2/2] resize: fix memory leak when exiting normally Wu Guanghao
0 siblings, 2 replies; 10+ messages in thread
From: Wu Guanghao @ 2025-11-18 13:25 UTC (permalink / raw)
To: tytso; +Cc: adilger.kernel, linux-ext4, yangyun50, wuguanghao3
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] 10+ messages in thread
* [PATCH 1/2] fsck: fix memory leak of inst->type
2025-11-18 13:25 [PATCH 0/2] e2fsprogs: fix memory leaks detected by ASAN Wu Guanghao
@ 2025-11-18 13:26 ` Wu Guanghao
2025-11-18 18:30 ` Darrick J. Wong
2025-11-18 13:26 ` [PATCH 2/2] resize: fix memory leak when exiting normally Wu Guanghao
1 sibling, 1 reply; 10+ messages in thread
From: Wu Guanghao @ 2025-11-18 13:26 UTC (permalink / raw)
To: tytso; +Cc: adilger.kernel, linux-ext4, 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] 10+ messages in thread
* [PATCH 2/2] resize: fix memory leak when exiting normally
2025-11-18 13:25 [PATCH 0/2] e2fsprogs: fix memory leaks detected by ASAN Wu Guanghao
2025-11-18 13:26 ` [PATCH 1/2] fsck: fix memory leak of inst->type Wu Guanghao
@ 2025-11-18 13:26 ` Wu Guanghao
2025-11-18 18:29 ` Darrick J. Wong
1 sibling, 1 reply; 10+ messages in thread
From: Wu Guanghao @ 2025-11-18 13:26 UTC (permalink / raw)
To: tytso; +Cc: adilger.kernel, linux-ext4, 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 | 2 ++
1 file changed, 2 insertions(+)
diff --git a/resize/main.c b/resize/main.c
index 08a4bbaf..71711229 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -702,6 +702,8 @@ int main (int argc, char ** argv)
}
if (fd > 0)
close(fd);
+
+ (void) ext2fs_close_free(&fs);
remove_error_table(&et_ext2_error_table);
return 0;
errout:
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] resize: fix memory leak when exiting normally
2025-11-18 13:26 ` [PATCH 2/2] resize: fix memory leak when exiting normally Wu Guanghao
@ 2025-11-18 18:29 ` Darrick J. Wong
2025-11-19 1:52 ` Wu Guanghao
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2025-11-18 18:29 UTC (permalink / raw)
To: Wu Guanghao; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
On Tue, Nov 18, 2025 at 09:26:01PM +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>
> ---
> resize/main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/resize/main.c b/resize/main.c
> index 08a4bbaf..71711229 100644
> --- a/resize/main.c
> +++ b/resize/main.c
> @@ -702,6 +702,8 @@ int main (int argc, char ** argv)
> }
> if (fd > 0)
> close(fd);
> +
> + (void) ext2fs_close_free(&fs);
You might want to capture and print an error if one is returned, because
ext2fs_close_free will also flush the new metadata to disk.
--D
> remove_error_table(&et_ext2_error_table);
> return 0;
> errout:
> --
> 2.27.0
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] fsck: fix memory leak of inst->type
2025-11-18 13:26 ` [PATCH 1/2] fsck: fix memory leak of inst->type Wu Guanghao
@ 2025-11-18 18:30 ` Darrick J. Wong
2025-11-19 1:25 ` Wu Guanghao
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2025-11-18 18:30 UTC (permalink / raw)
To: Wu Guanghao; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
On Tue, Nov 18, 2025 at 09:26:00PM +0800, Wu Guanghao wrote:
> The function free_instance() does not release i->type, resulting in a
> memory leak.
Does anyone still use this wrapper? I thought everyone used the
/sbin/fsck from util-linux...
--D
> 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 [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] fsck: fix memory leak of inst->type
2025-11-18 18:30 ` Darrick J. Wong
@ 2025-11-19 1:25 ` Wu Guanghao
2025-11-19 6:32 ` Darrick J. Wong
0 siblings, 1 reply; 10+ messages in thread
From: Wu Guanghao @ 2025-11-19 1:25 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
在 2025/11/19 2:30, Darrick J. Wong 写道:
> On Tue, Nov 18, 2025 at 09:26:00PM +0800, Wu Guanghao wrote:
>> The function free_instance() does not release i->type, resulting in a
>> memory leak.
>
> Does anyone still use this wrapper? I thought everyone used the
> /sbin/fsck from util-linux...
>
> --D
The issue was discovered while running the ext4 test cases in xfstests.
I cannot confirm whether other users are encountering the same problem,
but the issue definitely exists.
I also pushed a patch to fix a memory leak caused by duplicate memory
allocation in xfsprogs. If you have the time, could you please review it?
Thank you.
>
>> 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 [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] resize: fix memory leak when exiting normally
2025-11-18 18:29 ` Darrick J. Wong
@ 2025-11-19 1:52 ` Wu Guanghao
2025-11-19 6:26 ` Darrick J. Wong
0 siblings, 1 reply; 10+ messages in thread
From: Wu Guanghao @ 2025-11-19 1:52 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
在 2025/11/19 2:29, Darrick J. Wong 写道:
> On Tue, Nov 18, 2025 at 09:26:01PM +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>
>> ---
>> resize/main.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/resize/main.c b/resize/main.c
>> index 08a4bbaf..71711229 100644
>> --- a/resize/main.c
>> +++ b/resize/main.c
>> @@ -702,6 +702,8 @@ int main (int argc, char ** argv)
>> }
>> if (fd > 0)
>> close(fd);
>> +
>> + (void) ext2fs_close_free(&fs);
>
> You might want to capture and print an error if one is returned, because
> ext2fs_close_free will also flush the new metadata to disk.
>
> --D
>
This is not an error, but a normal process exit. If there is an error, it will follow the errout tag.
>> remove_error_table(&et_ext2_error_table);
>> return 0;
>> errout:
>> --
>> 2.27.0
>>
>>
>
>
> .
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] resize: fix memory leak when exiting normally
2025-11-19 1:52 ` Wu Guanghao
@ 2025-11-19 6:26 ` Darrick J. Wong
2025-11-20 3:45 ` Wu Guanghao
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2025-11-19 6:26 UTC (permalink / raw)
To: Wu Guanghao; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
On Wed, Nov 19, 2025 at 09:52:19AM +0800, Wu Guanghao wrote:
>
>
> 在 2025/11/19 2:29, Darrick J. Wong 写道:
> > On Tue, Nov 18, 2025 at 09:26:01PM +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>
> >> ---
> >> resize/main.c | 2 ++
> >> 1 file changed, 2 insertions(+)
> >>
> >> diff --git a/resize/main.c b/resize/main.c
> >> index 08a4bbaf..71711229 100644
> >> --- a/resize/main.c
> >> +++ b/resize/main.c
> >> @@ -702,6 +702,8 @@ int main (int argc, char ** argv)
> >> }
> >> if (fd > 0)
> >> close(fd);
> >> +
> >> + (void) ext2fs_close_free(&fs);
> >
> > You might want to capture and print an error if one is returned, because
> > ext2fs_close_free will also flush the new metadata to disk.
> >
> > --D
> >
> This is not an error, but a normal process exit. If there is an error,
> it will follow the errout tag.
I can see that, but I'm talking about capturing errors returned by
the new ext2fs_close_free call itself.
--D
> >> remove_error_table(&et_ext2_error_table);
> >> return 0;
> >> errout:
> >> --
> >> 2.27.0
> >>
> >>
> >
> >
> > .
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] fsck: fix memory leak of inst->type
2025-11-19 1:25 ` Wu Guanghao
@ 2025-11-19 6:32 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2025-11-19 6:32 UTC (permalink / raw)
To: Wu Guanghao; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
On Wed, Nov 19, 2025 at 09:25:00AM +0800, Wu Guanghao wrote:
>
>
> 在 2025/11/19 2:30, Darrick J. Wong 写道:
> > On Tue, Nov 18, 2025 at 09:26:00PM +0800, Wu Guanghao wrote:
> >> The function free_instance() does not release i->type, resulting in a
> >> memory leak.
> >
> > Does anyone still use this wrapper? I thought everyone used the
> > /sbin/fsck from util-linux...
> >
> > --D
>
> The issue was discovered while running the ext4 test cases in xfstests.
> I cannot confirm whether other users are encountering the same problem,
> but the issue definitely exists.
>
> I also pushed a patch to fix a memory leak caused by duplicate memory
> allocation in xfsprogs. If you have the time, could you please review it?
> Thank you.
Someone else already sent a fix patch last month.
--D
> >
> >> 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 [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] resize: fix memory leak when exiting normally
2025-11-19 6:26 ` Darrick J. Wong
@ 2025-11-20 3:45 ` Wu Guanghao
0 siblings, 0 replies; 10+ messages in thread
From: Wu Guanghao @ 2025-11-20 3:45 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: tytso, adilger.kernel, linux-ext4, yangyun50
在 2025/11/19 14:26, Darrick J. Wong 写道:
> On Wed, Nov 19, 2025 at 09:52:19AM +0800, Wu Guanghao wrote:
>>
>>
>> 在 2025/11/19 2:29, Darrick J. Wong 写道:
>>> On Tue, Nov 18, 2025 at 09:26:01PM +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>
>>>> ---
>>>> resize/main.c | 2 ++
>>>> 1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/resize/main.c b/resize/main.c
>>>> index 08a4bbaf..71711229 100644
>>>> --- a/resize/main.c
>>>> +++ b/resize/main.c
>>>> @@ -702,6 +702,8 @@ int main (int argc, char ** argv)
>>>> }
>>>> if (fd > 0)
>>>> close(fd);
>>>> +
>>>> + (void) ext2fs_close_free(&fs);
>>>
>>> You might want to capture and print an error if one is returned, because
>>> ext2fs_close_free will also flush the new metadata to disk.
>>>
>>> --D
>>>
>> This is not an error, but a normal process exit. If there is an error,
>> it will follow the errout tag.
>
> I can see that, but I'm talking about capturing errors returned by
> the new ext2fs_close_free call itself.
>
> --D
>
OK, I misunderstood. I will add a check in the next version.
>>>> remove_error_table(&et_ext2_error_table);
>>>> return 0;
>>>> errout:
>>>> --
>>>> 2.27.0
>>>>
>>>>
>>>
>>>
>>> .
>
> .
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-11-20 3:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18 13:25 [PATCH 0/2] e2fsprogs: fix memory leaks detected by ASAN Wu Guanghao
2025-11-18 13:26 ` [PATCH 1/2] fsck: fix memory leak of inst->type Wu Guanghao
2025-11-18 18:30 ` Darrick J. Wong
2025-11-19 1:25 ` Wu Guanghao
2025-11-19 6:32 ` Darrick J. Wong
2025-11-18 13:26 ` [PATCH 2/2] resize: fix memory leak when exiting normally Wu Guanghao
2025-11-18 18:29 ` Darrick J. Wong
2025-11-19 1:52 ` Wu Guanghao
2025-11-19 6:26 ` Darrick J. Wong
2025-11-20 3:45 ` Wu Guanghao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox