linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
Cc: namhyung@kernel.org, acme@kernel.org, peterz@infradead.org,
	 mingo@redhat.com, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com,  jolsa@kernel.org,
	adrian.hunter@intel.com, linux-perf-users@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] perf test pmu: Fix file Leak in test_format_dir_get
Date: Wed, 15 May 2024 14:14:15 -0700	[thread overview]
Message-ID: <CAP-5=fWBVwnhoeCtDTvHqZ6SGeOLAhD2GrshCRnwUvnNdyApQA@mail.gmail.com> (raw)
In-Reply-To: <20240515182750.489472-1-samasth.norway.ananda@oracle.com>

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
>

      reply	other threads:[~2024-05-15 21:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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='CAP-5=fWBVwnhoeCtDTvHqZ6SGeOLAhD2GrshCRnwUvnNdyApQA@mail.gmail.com' \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=samasth.norway.ananda@oracle.com \
    /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).