2021-07-12 16:25:32

by Colin King

[permalink] [raw]
Subject: [PATCH] gfs2: Fix memory leak of object lsi on error return path

From: Colin Ian King <[email protected]>

In the case where IS_ERR(lsi->si_sc_inode) is true the error exit path
to free_local does not kfree the allocated object lsi leading to a memory
leak. Fix this by kfree'ing lst before taking the error exit path.

Addresses-Coverity: ("Resource leak")
Fixes: 97fd734ba17e ("gfs2: lookup local statfs inodes prior to journal recovery")
Signed-off-by: Colin Ian King <[email protected]>
---
fs/gfs2/ops_fstype.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 5f4504dd0875..bd3b3be1a473 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -677,6 +677,7 @@ static int init_statfs(struct gfs2_sbd *sdp)
error = PTR_ERR(lsi->si_sc_inode);
fs_err(sdp, "can't find local \"sc\" file#%u: %d\n",
jd->jd_jid, error);
+ kfree(lsi);
goto free_local;
}
lsi->si_jid = jd->jd_jid;
--
2.31.1


2021-07-13 06:02:25

by Andreas Gruenbacher

[permalink] [raw]
Subject: Re: [PATCH] gfs2: Fix memory leak of object lsi on error return path

Hi Colin,

On Mon, Jul 12, 2021 at 6:24 PM Colin King <[email protected]> wrote:
>
> From: Colin Ian King <[email protected]>
>
> In the case where IS_ERR(lsi->si_sc_inode) is true the error exit path
> to free_local does not kfree the allocated object lsi leading to a memory
> leak. Fix this by kfree'ing lst before taking the error exit path.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 97fd734ba17e ("gfs2: lookup local statfs inodes prior to journal recovery")
> Signed-off-by: Colin Ian King <[email protected]>
> ---
> fs/gfs2/ops_fstype.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
> index 5f4504dd0875..bd3b3be1a473 100644
> --- a/fs/gfs2/ops_fstype.c
> +++ b/fs/gfs2/ops_fstype.c
> @@ -677,6 +677,7 @@ static int init_statfs(struct gfs2_sbd *sdp)
> error = PTR_ERR(lsi->si_sc_inode);
> fs_err(sdp, "can't find local \"sc\" file#%u: %d\n",
> jd->jd_jid, error);
> + kfree(lsi);
> goto free_local;
> }
> lsi->si_jid = jd->jd_jid;
> --
> 2.31.1

added to for-next.

Thanks,
Andreas