* [PATCH] selftests: prctl: Fix resource leaks
@ 2024-11-28 6:18 liujing
2024-12-04 23:00 ` Shuah Khan
0 siblings, 1 reply; 2+ messages in thread
From: liujing @ 2024-11-28 6:18 UTC (permalink / raw)
To: shuah, osmtendev; +Cc: linux-kselftest, linux-kernel, liujing
After using the fopen function successfully, you need to call
fclose to close the file before finally returning.
Signed-off-by: liujing <liujing@cmss.chinamobile.com>
diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
index 562f707ba771..7be7afff0cd2 100644
--- a/tools/testing/selftests/prctl/set-process-name.c
+++ b/tools/testing/selftests/prctl/set-process-name.c
@@ -66,9 +66,12 @@ int check_name(void)
return -EIO;
fscanf(fptr, "%s", output);
- if (ferror(fptr))
+ if (ferror(fptr)) {
+ fclose(fptr);
return -EIO;
+ }
+ fclose(fptr);
int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
if (res < 0)
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests: prctl: Fix resource leaks
2024-11-28 6:18 [PATCH] selftests: prctl: Fix resource leaks liujing
@ 2024-12-04 23:00 ` Shuah Khan
0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2024-12-04 23:00 UTC (permalink / raw)
To: liujing, shuah, osmtendev; +Cc: linux-kselftest, linux-kernel, Shuah Khan
On 11/27/24 23:18, liujing wrote:
> After using the fopen function successfully, you need to call
> fclose to close the file before finally returning.
>
> Signed-off-by: liujing <liujing@cmss.chinamobile.com>
>
> diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
> index 562f707ba771..7be7afff0cd2 100644
> --- a/tools/testing/selftests/prctl/set-process-name.c
> +++ b/tools/testing/selftests/prctl/set-process-name.c
> @@ -66,9 +66,12 @@ int check_name(void)
> return -EIO;
>
> fscanf(fptr, "%s", output);
> - if (ferror(fptr))
> + if (ferror(fptr)) {
> + fclose(fptr);
> return -EIO;
> + }
>
> + fclose(fptr);
> int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
>
> if (res < 0)
How did you find this problem? This file will be closed when
the test exits - do you need this fclose()?
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-04 23:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-28 6:18 [PATCH] selftests: prctl: Fix resource leaks liujing
2024-12-04 23:00 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox