From: Ding Xiang <dingxiang@cmss.chinamobile.com>
To: shuah@kernel.org, mic@digikod.net
Cc: linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] selftests/landlock: Fix a resource leak
Date: Wed, 30 Aug 2023 14:08:58 +0800 [thread overview]
Message-ID: <20230830060858.2841-1-dingxiang@cmss.chinamobile.com> (raw)
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;
+ }
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);
fclose(inf);
--
2.38.1
next reply other threads:[~2023-08-30 6:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 6:08 Ding Xiang [this message]
2023-08-30 9:01 ` [PATCH] selftests/landlock: Fix a resource leak Mickaël Salaün
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=20230830060858.2841-1-dingxiang@cmss.chinamobile.com \
--to=dingxiang@cmss.chinamobile.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--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 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.