linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gfs2: Fix memory leak of object lsi on error return path
@ 2021-07-12 16:24 Colin King
  2021-07-13  6:00 ` Andreas Gruenbacher
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-07-12 16:24 UTC (permalink / raw)
  To: Bob Peterson, Andreas Gruenbacher, Abhi Das, cluster-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gfs2: Fix memory leak of object lsi on error return path
  2021-07-12 16:24 [PATCH] gfs2: Fix memory leak of object lsi on error return path Colin King
@ 2021-07-13  6:00 ` Andreas Gruenbacher
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Gruenbacher @ 2021-07-13  6:00 UTC (permalink / raw)
  To: Colin King; +Cc: Bob Peterson, Abhi Das, cluster-devel, kernel-janitors, LKML

Hi Colin,

On Mon, Jul 12, 2021 at 6:24 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> 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 <colin.king@canonical.com>
> ---
>  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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-13  6:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 16:24 [PATCH] gfs2: Fix memory leak of object lsi on error return path Colin King
2021-07-13  6:00 ` Andreas Gruenbacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).