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);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to