From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758764AbbCETTx (ORCPT ); Thu, 5 Mar 2015 14:19:53 -0500 Received: from mail-lb0-f173.google.com ([209.85.217.173]:34845 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758707AbbCETTu (ORCPT ); Thu, 5 Mar 2015 14:19:50 -0500 Date: Thu, 5 Mar 2015 20:19:41 +0100 From: Rabin Vincent To: Arnaldo Carvalho de Melo Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , David Ahern , Jiri Olsa , Namhyung Kim , Paul Mackerras , Peter Zijlstra Subject: Re: [PATCH 1/1] perf annotate: Fix fallback to unparsed disassembler line Message-ID: <20150305191941.GA8759@dator> References: <1425582200-28125-1-git-send-email-acme@kernel.org> <1425582200-28125-2-git-send-email-acme@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1425582200-28125-2-git-send-email-acme@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 05, 2015 at 04:03:20PM -0300, Arnaldo Carvalho de Melo wrote: > When fixing a leak in the 0fb9f2aab738 commit ("perf annotate: Fix > memory leaks in LOCK handling") we failed to take that into account and > instead tried to free one of the data structures that should be freed > only when successfully allocated, oops, segfault. > > There was a change in the way the objdump output for lock prefixed > instructions is formatted that lead the relevant parser to fail to grok > it. > > At least RHEL7 works ok, but Fedora 20 segfaults. > > Fix it by making the ins__delete() destructor work like the most basic > destructor: free(). > > Namely make it accept a NULL pointer and when handling it just do > nothing. While this patch is certainly sufficient both as a safety and as a quick fix to the current problem (sorry about that), it seems that the real issue is that lock__parse() returns success even on parsing failures? The following patch fixes the issue for me without the above check. (The removal of locked.ins == NULL in lock__scnprintf() is because it becomes unused after this. On failure to parse the lock's inner instruction, the default printing in disasm__line__scnprintf() will be used, and that is identical to what this ins__raw_scnprintf() call does.) 8<------------ diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 61bf912..51ab850 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -171,7 +171,7 @@ static int lock__parse(struct ins_operands *ops) ops->locked.ops = zalloc(sizeof(*ops->locked.ops)); if (ops->locked.ops == NULL) - return 0; + return -1; if (disasm_line__parse(ops->raw, &name, &ops->locked.ops->raw) < 0) goto out_free_ops; @@ -193,7 +193,7 @@ static int lock__parse(struct ins_operands *ops) out_free_ops: zfree(&ops->locked.ops); - return 0; + return -1; } static int lock__scnprintf(struct ins *ins, char *bf, size_t size, @@ -201,9 +201,6 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size, { int printed; - if (ops->locked.ins == NULL) - return ins__raw_scnprintf(ins, bf, size, ops); - printed = scnprintf(bf, size, "%-6.6s ", ins->name); return printed + ins__scnprintf(ops->locked.ins, bf + printed, size - printed, ops->locked.ops);