Bug 265071 - ext2fs: fix potential memory leak in ext4_ext_grow_indepth()
Summary: ext2fs: fix potential memory leak in ext4_ext_grow_indepth()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Many People
Assignee: Fedor Uporov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-07 06:34 UTC by niejianglei2021@163.com
Modified: 2024-01-05 03:15 UTC (History)
3 users (show)

See Also:


Attachments
a possible patch to this bug. (1.50 KB, patch)
2022-07-07 07:16 UTC, niejianglei2021@163.com
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description niejianglei2021@163.com 2022-07-07 06:34:01 UTC
ext4_ext_grow_indepth() allocates memory chunk for "newblk" with
ext4_ext_alloc_meta(). When getblk() and bwrite() fail in this funciton,
"newblk" is not released, which will lead to a memory leak.

We should release the "newblk" with ext4_ext_blkfree() when some error
occurs to avoid the memory leak.
Comment 1 niejianglei2021@163.com 2022-07-07 06:35:33 UTC
ext4_ext_grow_indepth() allocates memory chunk for "newblk" with
ext4_ext_alloc_meta(). When getblk() and bwrite() fail in this funciton,
"newblk" is not released, which will lead to a memory leak.

We should release the "newblk" with ext4_ext_blkfree() when some error
occurs to avoid the memory leak.
Comment 2 niejianglei2021@163.com 2022-07-07 07:16:41 UTC
Created attachment 235103 [details]
a possible patch to this bug.
Comment 3 Pedro F. Giffuni freebsd_committer freebsd_triage 2022-07-08 20:36:50 UTC
LGTM, but Fedor wrote the code so he should approve.
Comment 4 Fedor Uporov freebsd_committer freebsd_triage 2022-07-12 13:04:18 UTC
Thanks for report.

I will commit this fix little bit later, together with some another patches.
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-12-17 18:21:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=38389acc59fcb014c5c9beed06a6f13835808b89

commit 38389acc59fcb014c5c9beed06a6f13835808b89
Author:     Pedro F. Giffuni <pfg@FreeBSD.org>
AuthorDate: 2022-12-17 18:19:51 +0000
Commit:     Pedro F. Giffuni <pfg@FreeBSD.org>
CommitDate: 2022-12-17 18:19:51 +0000

    ext2fs: fix potential memory leak in ext4_ext_grow_indepth()

    PR:     265071

 sys/fs/ext2fs/ext2_extents.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Comment 6 Fedor Uporov freebsd_committer freebsd_triage 2022-12-18 12:50:20 UTC
(In reply to commit-hook from comment #5)
Pedro, thank you for fix.
Comment 7 Mark Linimon freebsd_committer freebsd_triage 2024-01-05 03:15:53 UTC
^Triage: committed back in 2022.