* [PATCH RESEND] perf test pmu: Fix file Leak in test_format_dir_get
@ 2024-05-15 18:27 Samasth Norway Ananda
2024-05-15 21:14 ` Ian Rogers
0 siblings, 1 reply; 2+ messages in thread
From: Samasth Norway Ananda @ 2024-05-15 18:27 UTC (permalink / raw)
To: namhyung, acme
Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, linux-perf-users, linux-kernel,
samasth.norway.ananda
File is opened inside the for loop. But if the 'if' condition is
successful then 'break' statement will be reached, exiting the
'for' loop prior to reaching 'fclose'.
Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
---
Found this error through static analysis. This has only been compile
tested.
---
tools/perf/tests/pmu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
index 8f18127d876a..f751e6cb6ac0 100644
--- a/tools/perf/tests/pmu.c
+++ b/tools/perf/tests/pmu.c
@@ -106,8 +106,10 @@ static char *test_format_dir_get(char *dir, size_t sz)
if (!file)
return NULL;
- if (1 != fwrite(format->value, strlen(format->value), 1, file))
+ if (1 != fwrite(format->value, strlen(format->value), 1, file)) {
+ fclose(file);
break;
+ }
fclose(file);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND] perf test pmu: Fix file Leak in test_format_dir_get
2024-05-15 18:27 [PATCH RESEND] perf test pmu: Fix file Leak in test_format_dir_get Samasth Norway Ananda
@ 2024-05-15 21:14 ` Ian Rogers
0 siblings, 0 replies; 2+ messages in thread
From: Ian Rogers @ 2024-05-15 21:14 UTC (permalink / raw)
To: Samasth Norway Ananda
Cc: namhyung, acme, peterz, mingo, mark.rutland, alexander.shishkin,
jolsa, adrian.hunter, linux-perf-users, linux-kernel
On Wed, May 15, 2024 at 11:27 AM Samasth Norway Ananda
<samasth.norway.ananda@oracle.com> wrote:
>
> File is opened inside the for loop. But if the 'if' condition is
> successful then 'break' statement will be reached, exiting the
> 'for' loop prior to reaching 'fclose'.
>
> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
> ---
> Found this error through static analysis. This has only been compile
> tested.
Thanks Samasth, I agree with the fix however this code was recently
deleted and isn't in our next tree:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/pmu.c?h=perf-tools-next
the change that removed the code is:
https://lore.kernel.org/all/20240502213507.2339733-4-irogers@google.com/
Thanks,
Ian
> ---
> tools/perf/tests/pmu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
> index 8f18127d876a..f751e6cb6ac0 100644
> --- a/tools/perf/tests/pmu.c
> +++ b/tools/perf/tests/pmu.c
> @@ -106,8 +106,10 @@ static char *test_format_dir_get(char *dir, size_t sz)
> if (!file)
> return NULL;
>
> - if (1 != fwrite(format->value, strlen(format->value), 1, file))
> + if (1 != fwrite(format->value, strlen(format->value), 1, file)) {
> + fclose(file);
> break;
> + }
>
> fclose(file);
> }
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-15 21:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-15 18:27 [PATCH RESEND] perf test pmu: Fix file Leak in test_format_dir_get Samasth Norway Ananda
2024-05-15 21:14 ` Ian Rogers
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).