[PATCH v9 1/9] perf cs-etm: Fix thread leaks on trace queue init failure
James Clark
james.clark at linaro.org
Wed Jun 17 03:07:42 PDT 2026
On 16/06/2026 3:51 pm, Leo Yan wrote:
> cs_etm__init_traceid_queue() allocates the frontend and decode threads,
> if a later allocation fails, the error path does not drop thread
> reference that was already acquired.
>
> Release both thread pointers with thread__zput() on the error path, so
> does not leak thread references or leave stale pointers behind.
>
> Fixes: 951ccccdc715 ("perf cs-etm: Only track threads instead of PID and TIDs")
> Signed-off-by: Leo Yan <leo.yan at arm.com>
> ---
> tools/perf/util/cs-etm.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 0927b0b9c06b15046afeafe23fe170b8248cfcc6..d484a6155c2c22fa916d0365987302f6bb9978e9 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -627,6 +627,8 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
> queue->tid);
> tidq->decode_thread = machine__findnew_thread(&etm->session->machines.host, -1,
> queue->tid);
> + if (!tidq->frontend_thread || !tidq->decode_thread)
> + goto out;
>
> tidq->packet = zalloc(sizeof(struct cs_etm_packet));
> if (!tidq->packet)
> @@ -661,6 +663,8 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq,
> zfree(&tidq->prev_packet);
> zfree(&tidq->packet);
> out:
> + thread__zput(tidq->frontend_thread);
> + thread__zput(tidq->decode_thread);
> return rc;
> }
>
>
Reviewed-by: James Clark <james.clark at linaro.org>
More information about the linux-arm-kernel
mailing list