[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ec142501-1459-4fcb-94d6-b26290ce107c@linuxfoundation.org>
Date: Wed, 4 Dec 2024 16:09:33 -0700
From: Shuah Khan <skhan@...uxfoundation.org>
To: liujing <liujing@...s.chinamobile.com>, shuah@...nel.org
Cc: linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH] selftests/timens: Add fclose(proc) to prevent memory
leaks
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@...s.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
Powered by blists - more mailing lists