perf machine: Guard against NULL in machine__exit()

A recent fix for 'perf trace' introduced a bug where
machine__exit(trace->host) could be called while trace->host was still
NULL, so make this more robust by guarding against NULL, just like
free() does.

The problem happens, for instance, when !root users try to run 'perf

  [acme@jouet linux]$ trace
  Error:	No permissions to read /sys/kernel/debug/tracing/events/raw_syscalls/sys_(enter|exit)
  Hint:	Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing'

  perf: Segmentation fault
  Obtained 7 stack frames.
  /lib64/ [0x7f43a1dd971f]
  /lib64/ [0x7f43a1dc3509]
  Segmentation fault (core dumped)
  [acme@jouet linux]$

Cc: Adrian Hunter <>
Cc: Alexander Shishkin <>
Cc: Andrei Vagin <>
Cc: David Ahern <>
Cc: Jiri Olsa <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Vasily Averin <>
Cc: Wang Nan <>
Fixes: 33974a41 ("perf trace: Call machine__exit() at exit")
Signed-off-by: default avatarArnaldo Carvalho de Melo <>
parent 501e5bbe
......@@ -172,6 +172,9 @@ void machine__exit(struct machine *machine)
int i;
if (machine == NULL)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment