There is a segmentation fault bug in 'perf annotate' using the perf.data
created by 'perf record -g', so fix it.

Example:

 $ perf record -g ls

Before this patch:

 $ perf annotate
 Segmentation fault

After this patch:

 $ perf annotate
  Percent |      Source code & Disassembly of kcore for cycles
 -------------------------------------------------------------
          :
          :
          :
          :      Disassembly of section load0:
          :
          :      ffffffff8103efc0 <load0>:
     0.00 :        ffffffff8103efc0:       mov    %esi,%eax
     0.00 :        ffffffff8103efc2:       mov    %edi,%ecx
     0.00 :        ffffffff8103efc4:       wrmsr
   100.00 :        ffffffff8103efc6:       xor    %eax,%eax
     0.00 :        ffffffff8103efc8:       retq
  Percent |      Source code & Disassembly of kcore for cycles
 -------------------------------------------------------------
 ...

Signed-off-by: Yunlong Song <[email protected]>
---
 tools/perf/util/annotate.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 61bf912..0f9ebad 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -30,6 +30,9 @@ static int disasm_line__parse(char *line, char **namep, char 
**rawp);
 
 static void ins__delete(struct ins_operands *ops)
 {
+       if (ops == NULL)
+               return;
+
        zfree(&ops->source.raw);
        zfree(&ops->source.name);
        zfree(&ops->target.raw);
@@ -211,7 +214,11 @@ static int lock__scnprintf(struct ins *ins, char *bf, 
size_t size,
 
 static void lock__delete(struct ins_operands *ops)
 {
-       struct ins *ins = ops->locked.ins;
+       struct ins *ins;
+
+       if (ops == NULL)
+               return;
+       ins = ops->locked.ins;
 
        if (ins && ins->ops->free)
                ins->ops->free(ops->locked.ops);
-- 
1.8.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
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