linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>, Minchan Kim <minchan@kernel.org>,
	Joonsoo Kim <js1304@gmail.com>
Subject: [PATCH 1/6] perf kmem: Fix segfault when invalid sort key is given
Date: Thu, 12 Mar 2015 16:32:46 +0900	[thread overview]
Message-ID: <1426145571-3065-2-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1426145571-3065-1-git-send-email-namhyung@kernel.org>

When it tries to free 'str', it was already updated by strsep() - so
it needs to save the original pointer.

  # perf kmem stat -s xxx,hit
    Error: Unknown --sort key: 'xxx'
  *** Error in `perf': free(): invalid pointer: 0x0000000000e9e7b6 ***
  ======= Backtrace: =========
  /usr/lib/libc.so.6(+0x7198e)[0x7fc7e6e0d98e]
  /usr/lib/libc.so.6(+0x76dee)[0x7fc7e6e12dee]
  /usr/lib/libc.so.6(+0x775cb)[0x7fc7e6e135cb]
  ./perf[0x44a1b5]
  ./perf[0x490b20]
  ./perf(parse_options_step+0x173)[0x491773]
  ./perf(parse_options_subcommand+0xa7)[0x491fb7]
  ./perf(cmd_kmem+0x2bc)[0x44ae4c]
  ./perf[0x47aa13]
  ./perf(main+0x60a)[0x427a9a]
  /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7fc7e6dbc800]
  ./perf(_start+0x29)[0x427bb9]

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-kmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index f295141025bc..a0da5fb44b9e 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -559,6 +559,7 @@ static int setup_sorting(struct list_head *sort_list, const char *arg)
 {
 	char *tok;
 	char *str = strdup(arg);
+	char *pos = str;
 
 	if (!str) {
 		pr_err("%s: strdup failed\n", __func__);
@@ -566,7 +567,7 @@ static int setup_sorting(struct list_head *sort_list, const char *arg)
 	}
 
 	while (true) {
-		tok = strsep(&str, ",");
+		tok = strsep(&pos, ",");
 		if (!tok)
 			break;
 		if (sort_dimension__add(tok, sort_list) < 0) {
-- 
2.3.1


  reply	other threads:[~2015-03-12  7:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-12  7:32 [RFC/PATCHSET 0/6] perf kmem: Implement page allocation analysis (v1) Namhyung Kim
2015-03-12  7:32 ` Namhyung Kim [this message]
2015-03-14  7:06   ` [tip:perf/core] perf kmem: Fix segfault when invalid sort key is given tip-bot for Namhyung Kim
2015-03-12  7:32 ` [PATCH 2/6] perf kmem: Allow -v option Namhyung Kim
2015-03-14  7:06   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-03-12  7:32 ` [PATCH 3/6] perf kmem: Fix alignment of slab result table Namhyung Kim
2015-03-14  7:07   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-03-12  7:32 ` [PATCH 4/6] perf kmem: Analyze page allocator events also Namhyung Kim
2015-03-12 11:01   ` Jiri Olsa
2015-03-12 15:11     ` Namhyung Kim
2015-03-12  7:32 ` [PATCH 5/6] perf kmem: Implement stat --page --caller Namhyung Kim
2015-03-12  7:32 ` [PATCH 6/6] perf kmem: Support sort keys on page analysis Namhyung Kim
2015-03-12 10:41 ` [RFC/PATCHSET 0/6] perf kmem: Implement page allocation analysis (v1) Ingo Molnar
2015-03-12 14:58   ` Namhyung Kim
2015-03-12 15:54     ` Ingo Molnar
2015-03-13  8:19       ` Namhyung Kim
2015-03-13 12:44         ` Ingo Molnar
2015-03-16  2:06           ` Namhyung Kim
2015-03-16  2:10     ` Namhyung Kim
2015-03-16  8:26       ` Ingo Molnar
2015-03-16  8:35         ` Namhyung Kim
2015-03-16  8:43           ` Ingo Molnar
2015-03-12 19:07   ` Arnaldo Carvalho de Melo

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=1426145571-3065-2-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=js1304@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=mingo@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).