Skip to content

perf trace: Tracepoint format error handling and leak fixes

Ian Rogers linux-perf-users lkml 1 version Applied

Status from this message: Thanks, applied to perf-tools-next, for v7.4.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 1 replyApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/5perf trace-event: Report tracepoint format errors with NULL and errnotools/perf/builtin-kmem.c tools/perf/builtin-sched.c tools/perf/builtin-trace.c +2 more+47 -280 replies
2/5perf trace-event: Reuse an already parsed tracepoint formattools/perf/util/trace-event.c+14 -20 replies
3/5perf trace-event: Free the global trace_event when a command endstools/perf/perf.c tools/perf/util/trace-event.c tools/perf/util/trace-event.h+24 -50 replies
4/5perf trace: Free the host machine allocationtools/perf/builtin-trace.c+1 -10 replies
5/5perf thread: Free the comm read from procfstools/perf/util/thread.c+5 -50 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH v1 0/5] perf trace: Tracepoint format error handling and leak fixes

Running 'perf trace' under address sanitizer turned up a handful of problems around the global tracepoint format cache.

trace_event__tp_format() encoded failures with ERR_PTR(), but trace_event__tp_format_id() returned a plain NULL when the lookup missed and tp_format() discarded the return value of tep_parse_format(), so two of the three failure modes were indistinguishable from success to a caller using IS_ERR(). syscall__read_info() then dereferenced the NULL. Patch 1 drops the error pointers and reports failures as NULL with errno set, which is what the callers were already testing for.

Patch 2 stops re-reading and re-parsing a format file that has already been parsed. Each parse adds another tep_event to the handle and libtraceevent can only free the whole handle, so a repeated lookup left a duplicate behind for the rest of the session.

Patch 3 finally does what the TODO above the global has asked for since the code was added, and frees the handle once the command is done.

That in turn exposed two leaks that had been hidden because the handle kept them reachable: patch 4 frees the machine created by machine__new_host(), which was released with machine__exit() rather than machine__delete() and so leaked the allocation itself, and patch 5 frees the buffer procfs__read_str() hands to thread__set_comm_from_proc(), which is only freed when the read comes back empty.

With these, and with an unrelated libtraceevent fix I will send separately to linux-trace-devel, 'perf trace' exits with no leaks reported.

Tested on x86_64. Every patch builds individually, and the series also builds with NO_LIBTRACEEVENT=1.

Ian Rogers (5):
perf trace-event: Report tracepoint format errors with NULL and errno perf trace-event: Reuse an already parsed tracepoint format perf trace-event: Free the global trace_event when a command ends perf trace: Free the host machine allocation
perf thread: Free the comm read from procfs

 tools/perf/builtin-kmem.c     |  3 +-
 tools/perf/builtin-sched.c    |  5 +-
 tools/perf/builtin-trace.c    | 12 ++---
 tools/perf/perf.c             |  6 +++
 tools/perf/util/evsel.c       |  5 +-
 tools/perf/util/thread.c      | 10 ++--
 tools/perf/util/trace-event.c | 90 +++++++++++++++++++++++++++--------
 tools/perf/util/trace-event.h |  1 +
 8 files changed, 91 insertions(+), 41 deletions(-)
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog