perf sort: Fix a memory leak on srcline
authorNamhyung Kim <namhyung.kim@lge.com>
Wed, 11 Sep 2013 05:09:25 +0000 (14:09 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 9 Oct 2013 18:58:07 +0000 (15:58 -0300)
In the hist_entry__srcline_snprintf(), path and self->srcline are
pointing the same memory region, but they are doubly allocated.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1378876173-13363-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/sort.c

index b4ecc0e4c908da0fe698849198b50963e6ef558a..97cf3ef4417c6496e5516cdd0e4e86891add4173 100644 (file)
@@ -269,10 +269,7 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
        if (!fp)
                goto out_ip;
 
-       if (getline(&path, &line_len, fp) < 0 || !line_len)
-               goto out_ip;
-       self->srcline = strdup(path);
-       if (self->srcline == NULL)
+       if (getline(&self->srcline, &line_len, fp) < 0 || !line_len)
                goto out_ip;
 
        nl = strchr(self->srcline, '\n');