mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 03/20] perf trace: Fixup thread refcounting
Date: Mon, 27 Mar 2017 22:38:58 -0300	[thread overview]
Message-ID: <20170328013915.15236-4-acme@kernel.org> (raw)
In-Reply-To: <20170328013915.15236-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 2425605461fe..60053d49539b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1653,17 +1653,17 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
 
 	ttrace = thread__priv(thread);
 	if (!ttrace)
-		goto out;
+		goto out_put;
 
 	filename_len = strlen(filename);
 	if (filename_len == 0)
-		goto out;
+		goto out_put;
 
 	if (ttrace->filename.namelen < filename_len) {
 		char *f = realloc(ttrace->filename.name, filename_len + 1);
 
 		if (f == NULL)
-			goto out;
+			goto out_put;
 
 		ttrace->filename.namelen = filename_len;
 		ttrace->filename.name = f;
@@ -1673,12 +1673,12 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
 	ttrace->filename.pending_open = true;
 
 	if (!ttrace->filename.ptr)
-		goto out;
+		goto out_put;
 
 	entry_str_len = strlen(ttrace->entry_str);
 	remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */
 	if (remaining_space <= 0)
-		goto out;
+		goto out_put;
 
 	if (filename_len > (size_t)remaining_space) {
 		filename += filename_len - remaining_space;
@@ -1692,6 +1692,8 @@ static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel,
 
 	ttrace->filename.ptr = 0;
 	ttrace->filename.entry_str_pos = 0;
+out_put:
+	thread__put(thread);
 out:
 	return 0;
 }
@@ -1712,6 +1714,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs
 
 	ttrace->runtime_ms += runtime_ms;
 	trace->runtime_ms += runtime_ms;
+out_put:
 	thread__put(thread);
 	return 0;
 
@@ -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"),
 	       runtime,
 	       perf_evsel__intval(evsel, sample, "vruntime"));
-	thread__put(thread);
-	return 0;
+	goto out_put;
 }
 
 static void bpf_output__printer(enum binary_printer_ops op,
@@ -1922,7 +1924,7 @@ static int trace__process_sample(struct perf_tool *tool,
 
 	thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
 	if (thread && thread__is_filtered(thread))
-		return 0;
+		goto out;
 
 	trace__set_base_time(trace, evsel, sample);
 
@@ -1930,7 +1932,8 @@ static int trace__process_sample(struct perf_tool *tool,
 		++trace->nr_events;
 		handler(trace, evsel, event, sample);
 	}
-
+out:
+	thread__put(thread);
 	return err;
 }
 
-- 
2.9.3

  parent reply	other threads:[~2017-03-28  1:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28  1:38 [GIT PULL 00/20] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-03-28  1:38 ` [PATCH 01/20] perf trace: Check for vfs_getname.pathname length Arnaldo Carvalho de Melo
2017-03-28  1:38 ` [PATCH 02/20] perf trace: Fix up error path indentation Arnaldo Carvalho de Melo
2017-03-28  1:38 ` Arnaldo Carvalho de Melo [this message]
2017-03-28  1:38 ` [PATCH 04/20] perf auxtrace: Fix no_size logic in addr_filter__resolve_kernel_syms() Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 05/20] perf list sdt: Show option in man page Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 06/20] perf tools: Remove unused 'prefix' from builtin functions Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 07/20] perf report: Refactor common code in srcline.c Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 08/20] perf report: Find the inline stack for a given address Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 09/20] perf report: Introduce --inline option Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 10/20] perf report: Show inline stack for stdio mode Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 11/20] perf report: Show inline stack for browser mode Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 12/20] perf report: Enable sorting by srcline as key Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 13/20] perf annotate: Fix a bug following symbolic link of a build-id file Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 14/20] perf annotate: Fix a bug of division by zero when calculating percent Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 15/20] perf buildid: Do not update SDT cache with null filename Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 16/20] perf buildid: Do not assume that readlink() returns a null terminated string Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 17/20] perf tests: " Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 18/20] perf utils: use sizeof(buf) - 1 in readlink() call Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 19/20] perf utils: Null terminate buf in read_ftrace_printk() Arnaldo Carvalho de Melo
2017-03-28  1:39 ` [PATCH 20/20] perf utils: Readlink /proc/self/exe to find the perf binary Arnaldo Carvalho de Melo
2017-03-28  5:45 ` [GIT PULL 00/20] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170328013915.15236-4-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome