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] selftests/landlock: Fix a resource leak
Date: Wed, 30 Aug 2023 11:01:47 +0200 [thread overview]
Message-ID: <20230830.Ahqu4iepha4I@digikod.net> (raw)
In-Reply-To: <20230830060858.2841-1-dingxiang@cmss.chinamobile.com>
Hi,
Thanks for this fix. A few suggestions:
On Wed, Aug 30, 2023 at 02:08:58PM +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, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 83d565569512..687a66ea9799 100644
> --- a/tools/testing/selftests/landlock/fs_test.c
> +++ b/tools/testing/selftests/landlock/fs_test.c
> @@ -124,13 +124,17 @@ static bool supports_filesystem(const char *const filesystem)
> return true;
>
> /* filesystem can be null for bind mounts. */
> - if (!filesystem)
> + if (!filesystem) {
> + fclose(inf);
> return true;
Can you please change these two lines (and the next hunk) with a
`goto out` (and then don't add the if braces), initialize res to true
when it is declared, and add the `out` label below?
> + }
>
> len = snprintf(str, sizeof(str), "nodev\t%s\n", filesystem);
> - if (len >= sizeof(str))
> + if (len >= sizeof(str)) {
> + fclose(inf);
> /* Ignores too-long filesystem names. */
> return true;
> + }
>
> res = fgrep(inf, str);
out:
> fclose(inf);
> --
> 2.38.1
>
>
>
prev parent reply other threads:[~2023-08-30 18:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 6:08 [PATCH] selftests/landlock: Fix a resource leak Ding Xiang
2023-08-30 9:01 ` 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.Ahqu4iepha4I@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).