diff options
author | Chenggang Qin <chenggang.qcg@taobao.com> | 2013-10-10 20:27:57 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-14 11:21:23 -0400 |
commit | 784f3390f9bd900adfb3b0373615e105a0d9749a (patch) | |
tree | da35f0ffc970ef9b1348ae9179c5cde2843d68f9 /tools | |
parent | d4f74eb89199dc7bde5579783e9188841e1271e3 (diff) |
perf symbols: Fix a mmap and munmap mismatched bug
In function filename__read_debuglink(), while the ELF file is opend and
mmapped in elf_begin(), but if this file is considered to not be usable
during the following code, we will goto the close(fd) directly. The
elf_end() is skipped. So, the mmaped ELF file cannot be munmapped. The
mmapped areas exist during the life of perf.
This is a memory leak. This patch fixed this bug.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Chenggang Qin <chenggang.qcg@taobao.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Yanmin Zhang <yanmin.zhang@intel.com>
Link: http://lkml.kernel.org/r/1381451279-4109-1-git-send-email-chenggang.qin@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/symbol-elf.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index d6b8af3ce344..eed0b96302af 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c | |||
@@ -487,27 +487,27 @@ int filename__read_debuglink(const char *filename, char *debuglink, | |||
487 | 487 | ||
488 | ek = elf_kind(elf); | 488 | ek = elf_kind(elf); |
489 | if (ek != ELF_K_ELF) | 489 | if (ek != ELF_K_ELF) |
490 | goto out_close; | 490 | goto out_elf_end; |
491 | 491 | ||
492 | if (gelf_getehdr(elf, &ehdr) == NULL) { | 492 | if (gelf_getehdr(elf, &ehdr) == NULL) { |
493 | pr_err("%s: cannot get elf header.\n", __func__); | 493 | pr_err("%s: cannot get elf header.\n", __func__); |
494 | goto out_close; | 494 | goto out_elf_end; |
495 | } | 495 | } |
496 | 496 | ||
497 | sec = elf_section_by_name(elf, &ehdr, &shdr, | 497 | sec = elf_section_by_name(elf, &ehdr, &shdr, |
498 | ".gnu_debuglink", NULL); | 498 | ".gnu_debuglink", NULL); |
499 | if (sec == NULL) | 499 | if (sec == NULL) |
500 | goto out_close; | 500 | goto out_elf_end; |
501 | 501 | ||
502 | data = elf_getdata(sec, NULL); | 502 | data = elf_getdata(sec, NULL); |
503 | if (data == NULL) | 503 | if (data == NULL) |
504 | goto out_close; | 504 | goto out_elf_end; |
505 | 505 | ||
506 | /* the start of this section is a zero-terminated string */ | 506 | /* the start of this section is a zero-terminated string */ |
507 | strncpy(debuglink, data->d_buf, size); | 507 | strncpy(debuglink, data->d_buf, size); |
508 | 508 | ||
509 | out_elf_end: | ||
509 | elf_end(elf); | 510 | elf_end(elf); |
510 | |||
511 | out_close: | 511 | out_close: |
512 | close(fd); | 512 | close(fd); |
513 | out: | 513 | out: |