All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Khaled ROMDHANI <khaledromdhani216@gmail.com>
Cc: sfrench@samba.org, linux-cifs@vger.kernel.org,
	samba-technical@lists.samba.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH-next] fs/cifs: Fix resource leak
Date: Tue, 4 May 2021 16:44:45 +0300	[thread overview]
Message-ID: <20210504134244.GW1981@kadam> (raw)
In-Reply-To: <20210504124343.22611-1-khaledromdhani216@gmail.com>

On Tue, May 04, 2021 at 01:43:43PM +0100, Khaled ROMDHANI wrote:
> The -EIO error return path is leaking memory allocated
> to page. Fix this by invoking the free_dentry_path before
> the return.
> 
> Addresses-Coverity: ("Resource leak")
> Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>

Add a Fixes tag.

Fixes: 583248493f78 ("cifs: add shutdown support")

> ---
>  fs/cifs/link.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
> index 1cbe7ec73728..1485c6095ba1 100644
> --- a/fs/cifs/link.c
> +++ b/fs/cifs/link.c
> @@ -686,8 +686,10 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
>  	void *page = alloc_dentry_path();
>  	struct inode *newinode = NULL;
>  
> -	if (unlikely(cifs_forced_shutdown(cifs_sb)))
> +	if (unlikely(cifs_forced_shutdown(cifs_sb))) {
> +		free_dentry_path(page);
>  		return -EIO;
> +	}

Better to move the allocation here.  Avoid calling functions which can
fail in the declaration block.  Better to test for NULL directly instead
of hiding the test inside the build_path_from_dentry() function.

	page = alloc_dentry_path();
	if (!page)
		return -ENOMEM;

The error handling in this function is slightly unweildy...

regards,
dan carpenter


  reply	other threads:[~2021-05-04 13:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 12:43 [PATCH-next] fs/cifs: Fix resource leak Khaled ROMDHANI
2021-05-04 13:44 ` Dan Carpenter [this message]
2021-05-04 14:14   ` Khaled Romdhani
  -- strict thread matches above, loose matches on Subject: below --
2021-05-04 13:22 Khaled ROMDHANI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210504134244.GW1981@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=khaledromdhani216@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.