* [PATCH] perf tools: Put the function return operation at the end of the function
@ 2023-10-12 3:10 Kunwu.Chan
2023-10-12 5:02 ` Adrian Hunter
0 siblings, 1 reply; 3+ messages in thread
From: Kunwu.Chan @ 2023-10-12 3:10 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, irogers, adrian.hunter, kan.liang, seanjc,
kprateek.nayak, robert.richter
Cc: linux-perf-users, linux-kernel, kunwu.chan, Kunwu.Chan
Function return operations should be performed after resource release.
Fixes: 4e1b9c679fcb ("perf tools: Refactor print_event_desc()")
Signed-off-by: Kunwu.Chan <chentao@kylinos.cn>
---
| 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d812e1e371a7..5763f21844b1 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1998,13 +1998,14 @@ static struct evsel *read_event_desc(struct feat_fd *ff)
id++;
}
}
-out:
- free(buf);
- return events;
+
error:
free_event_desc(events);
events = NULL;
- goto out;
+
+out:
+ free(buf);
+ return events;
}
static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf tools: Put the function return operation at the end of the function
2023-10-12 3:10 [PATCH] perf tools: Put the function return operation at the end of the function Kunwu.Chan
@ 2023-10-12 5:02 ` Adrian Hunter
2023-10-12 6:53 ` [PATCH v2] " Kunwu.Chan
0 siblings, 1 reply; 3+ messages in thread
From: Adrian Hunter @ 2023-10-12 5:02 UTC (permalink / raw)
To: Kunwu.Chan, peterz, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, namhyung, irogers, kan.liang, seanjc,
kprateek.nayak, robert.richter
Cc: linux-perf-users, linux-kernel, kunwu.chan
On 12/10/23 06:10, Kunwu.Chan wrote:
> Function return operations should be performed after resource release.
>
> Fixes: 4e1b9c679fcb ("perf tools: Refactor print_event_desc()")
> Signed-off-by: Kunwu.Chan <chentao@kylinos.cn>
> ---
> tools/perf/util/header.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index d812e1e371a7..5763f21844b1 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -1998,13 +1998,14 @@ static struct evsel *read_event_desc(struct feat_fd *ff)
> id++;
> }
> }
> -out:
> - free(buf);
> - return events;
> +
> error:
> free_event_desc(events);
> events = NULL;
Always freeing the events is wrong. That path is only for errors.
That would show up if this had been tested.
> - goto out;
> +
> +out:
> + free(buf);
> + return events;
> }
>
> static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] perf tools: Put the function return operation at the end of the function
2023-10-12 5:02 ` Adrian Hunter
@ 2023-10-12 6:53 ` Kunwu.Chan
0 siblings, 0 replies; 3+ messages in thread
From: Kunwu.Chan @ 2023-10-12 6:53 UTC (permalink / raw)
To: adrian.hunter
Cc: acme, alexander.shishkin, chentao, irogers, jolsa, kan.liang,
kprateek.nayak, kunwu.chan, linux-kernel, linux-perf-users,
mark.rutland, mingo, namhyung, peterz, robert.richter, seanjc
All error paths go to the Release events process, while under normal
circumstances, go directly to the out process.
Fixes: 4e1b9c679fcb ("perf tools: Refactor print_event_desc()")
Signed-off-by: Kunwu.Chan <chentao@kylinos.cn>
---
| 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d812e1e371a7..c2f23381a9c6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1998,13 +1998,14 @@ static struct evsel *read_event_desc(struct feat_fd *ff)
id++;
}
}
-out:
- free(buf);
- return events;
+goto out;
error:
free_event_desc(events);
events = NULL;
- goto out;
+
+out:
+ free(buf);
+ return events;
}
static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
--
2.25.1
Sorry, the wrong patch was sent. The correct patch should be v2 as follows.
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-12 6:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 3:10 [PATCH] perf tools: Put the function return operation at the end of the function Kunwu.Chan
2023-10-12 5:02 ` Adrian Hunter
2023-10-12 6:53 ` [PATCH v2] " Kunwu.Chan
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).