linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: Ding Xiang <dingxiang@cmss.chinamobile.com>
Cc: shuah@kernel.org, linux-security-module@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] selftests/landlock: Fix a resource leak
Date: Wed, 30 Aug 2023 19:04:59 +0200	[thread overview]
Message-ID: <20230830.paiqu8Caew1X@digikod.net> (raw)
In-Reply-To: <20230830101148.3738-1-dingxiang@cmss.chinamobile.com>

Applied to my next tree. Thanks!

On Wed, Aug 30, 2023 at 06:11:48PM +0800, Ding Xiang wrote:
> The opened file should be closed before return,
> otherwise resource leak will occur
> 
> Signed-off-by: Ding Xiang <dingxiang@cmss.chinamobile.com>
> ---
>  tools/testing/selftests/landlock/fs_test.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 83d565569512..251594306d40 100644
> --- a/tools/testing/selftests/landlock/fs_test.c
> +++ b/tools/testing/selftests/landlock/fs_test.c
> @@ -113,7 +113,7 @@ static bool supports_filesystem(const char *const filesystem)
>  {
>  	char str[32];
>  	int len;
> -	bool res;
> +	bool res = true;
>  	FILE *const inf = fopen("/proc/filesystems", "r");
>  
>  	/*
> @@ -125,14 +125,16 @@ static bool supports_filesystem(const char *const filesystem)
>  
>  	/* filesystem can be null for bind mounts. */
>  	if (!filesystem)
> -		return true;
> +		goto out;
>  
>  	len = snprintf(str, sizeof(str), "nodev\t%s\n", filesystem);
>  	if (len >= sizeof(str))
>  		/* Ignores too-long filesystem names. */
> -		return true;
> +		goto out;
>  
>  	res = fgrep(inf, str);
> +
> +out:
>  	fclose(inf);
>  	return res;
>  }
> -- 
> 2.38.1
> 
> 
> 

      reply	other threads:[~2023-08-30 18:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 10:11 [PATCH v1] selftests/landlock: Fix a resource leak Ding Xiang
2023-08-30 17:04 ` Mickaël Salaün [this message]

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=20230830.paiqu8Caew1X@digikod.net \
    --to=mic@digikod.net \
    --cc=dingxiang@cmss.chinamobile.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=shuah@kernel.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 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).