From: Shuah Khan <skhan@linuxfoundation.org>
To: Ding Xiang <dingxiang@cmss.chinamobile.com>,
akpm@linux-foundation.org, shuah@kernel.org
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests: vm: Fix resource leak when return error
Date: Thu, 16 Jun 2022 14:11:30 -0600 [thread overview]
Message-ID: <29be48c7-7178-6f25-c99b-0d11eb967539@linuxfoundation.org> (raw)
In-Reply-To: <20220615093629.1330809-1-dingxiang@cmss.chinamobile.com>
On 6/15/22 3:36 AM, Ding Xiang wrote:
> When return on an error path, file handle need to be closed
> to prevent resource leak
>
> Signed-off-by: Ding Xiang <dingxiang@cmss.chinamobile.com>
> ---
> tools/testing/selftests/vm/ksm_tests.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/testing/selftests/vm/ksm_tests.c b/tools/testing/selftests/vm/ksm_tests.c
> index 2fcf24312da8..f5e4e0bbd081 100644
> --- a/tools/testing/selftests/vm/ksm_tests.c
> +++ b/tools/testing/selftests/vm/ksm_tests.c
> @@ -54,6 +54,7 @@ static int ksm_write_sysfs(const char *file_path, unsigned long val)
> }
> if (fprintf(f, "%lu", val) < 0) {
> perror("fprintf");
> + fclose(f);
> return 1;
> }
> fclose(f);
> @@ -72,6 +73,7 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val)
> }
> if (fscanf(f, "%lu", val) != 1) {
> perror("fscanf");
> + fclose(f);
> return 1;
> }
> fclose(f);
>
Looks good to me.
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
thanks,
-- Shuah
next prev parent reply other threads:[~2022-06-16 20:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-15 9:36 [PATCH] selftests: vm: Fix resource leak when return error Ding Xiang
2022-06-16 20:11 ` Shuah Khan [this message]
2022-06-16 20:19 ` Shuah Khan
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=29be48c7-7178-6f25-c99b-0d11eb967539@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=dingxiang@cmss.chinamobile.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.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).