perf trace: Fixup thread refcounting

In trace__vfs_getname() and when checking if a thread is filtered in
trace__process_sample() we were not dropping the reference obtained via
machine__findnew_thread(), fix it.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9gc470phavxwxv5d9w7ck8ev@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c04dfafa
...@@ -1653,17 +1653,17 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, ...@@ -1653,17 +1653,17 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
ttrace = thread__priv(thread); ttrace = thread__priv(thread);
if (!ttrace) if (!ttrace)
goto out; goto out_put;
filename_len = strlen(filename); filename_len = strlen(filename);
if (filename_len == 0) if (filename_len == 0)
goto out; goto out_put;
if (ttrace->filename.namelen < filename_len) { if (ttrace->filename.namelen < filename_len) {
char *f = realloc(ttrace->filename.name, filename_len + 1); char *f = realloc(ttrace->filename.name, filename_len + 1);
if (f == NULL) if (f == NULL)
goto out; goto out_put;
ttrace->filename.namelen = filename_len; ttrace->filename.namelen = filename_len;
ttrace->filename.name = f; ttrace->filename.name = f;
...@@ -1673,12 +1673,12 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, ...@@ -1673,12 +1673,12 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
ttrace->filename.pending_open = true; ttrace->filename.pending_open = true;
if (!ttrace->filename.ptr) if (!ttrace->filename.ptr)
goto out; goto out_put;
entry_str_len = strlen(ttrace->entry_str); entry_str_len = strlen(ttrace->entry_str);
remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */ remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */
if (remaining_space <= 0) if (remaining_space <= 0)
goto out; goto out_put;
if (filename_len > (size_t)remaining_space) { if (filename_len > (size_t)remaining_space) {
filename += filename_len - remaining_space; filename += filename_len - remaining_space;
...@@ -1692,6 +1692,8 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, ...@@ -1692,6 +1692,8 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
ttrace->filename.ptr = 0; ttrace->filename.ptr = 0;
ttrace->filename.entry_str_pos = 0; ttrace->filename.entry_str_pos = 0;
out_put:
thread__put(thread);
out: out:
return 0; return 0;
} }
...@@ -1712,6 +1714,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs ...@@ -1712,6 +1714,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs
ttrace->runtime_ms += runtime_ms; ttrace->runtime_ms += runtime_ms;
trace->runtime_ms += runtime_ms; trace->runtime_ms += runtime_ms;
out_put:
thread__put(thread); thread__put(thread);
return 0; return 0;
...@@ -1722,8 +1725,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs ...@@ -1722,8 +1725,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs
(pid_t)perf_evsel__intval(evsel, sample, "pid"), (pid_t)perf_evsel__intval(evsel, sample, "pid"),
runtime, runtime,
perf_evsel__intval(evsel, sample, "vruntime")); perf_evsel__intval(evsel, sample, "vruntime"));
thread__put(thread); goto out_put;
return 0;
} }
static void bpf_output__printer(enum binary_printer_ops op, static void bpf_output__printer(enum binary_printer_ops op,
...@@ -1922,7 +1924,7 @@ static int trace__process_sample(struct perf_tool *tool, ...@@ -1922,7 +1924,7 @@ static int trace__process_sample(struct perf_tool *tool,
thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
if (thread && thread__is_filtered(thread)) if (thread && thread__is_filtered(thread))
return 0; goto out;
trace__set_base_time(trace, evsel, sample); trace__set_base_time(trace, evsel, sample);
...@@ -1930,7 +1932,8 @@ static int trace__process_sample(struct perf_tool *tool, ...@@ -1930,7 +1932,8 @@ static int trace__process_sample(struct perf_tool *tool,
++trace->nr_events; ++trace->nr_events;
handler(trace, evsel, event, sample); handler(trace, evsel, event, sample);
} }
out:
thread__put(thread);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment