mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: liujing <liujing@cmss.chinamobile.com>, shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests/timens: Add fclose(proc) to prevent memory leaks
Date: Wed, 4 Dec 2024 16:09:33 -0700	[thread overview]
Message-ID: <ec142501-1459-4fcb-94d6-b26290ce107c@linuxfoundation.org> (raw)
In-Reply-To: <20241128060512.3948-1-liujing@cmss.chinamobile.com>

On 11/27/24 23:05, liujing wrote:
> If fopen succeeds, the fscanf function is called to read the data.
> Regardless of whether fscanf is successful, you need to run
> fclose(proc) to prevent memory leaks.
> 
> Signed-off-by: liujing <liujing@cmss.chinamobile.com>
> 
> diff --git a/tools/testing/selftests/timens/procfs.c b/tools/testing/selftests/timens/procfs.c
> index 1833ca97eb24..e47844a73c31 100644
> --- a/tools/testing/selftests/timens/procfs.c
> +++ b/tools/testing/selftests/timens/procfs.c
> @@ -79,9 +79,11 @@ static int read_proc_uptime(struct timespec *uptime)
>   	if (fscanf(proc, "%lu.%02lu", &up_sec, &up_nsec) != 2) {
>   		if (errno) {
>   			pr_perror("fscanf");
> +			fclose(proc);
>   			return -errno;
>   		}
>   		pr_err("failed to parse /proc/uptime");
> +		fclose(proc);
>   		return -1;
>   	}
>   	fclose(proc);

How did you find this problem? This file will be closed when
test exits? What does strace show you?

thanks,
-- Shuah



      reply	other threads:[~2024-12-04 23:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28  6:05 liujing
2024-12-04 23:09 ` Shuah Khan [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=ec142501-1459-4fcb-94d6-b26290ce107c@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liujing@cmss.chinamobile.com \
    --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

all inboxes | Powered by JetHome®