perf core: Fix a bug that lead to mmap() & munmap() mismatch
PATCH 1/1 perf core: Fix a bug that lead to mmap() & munmap() mismatch
From: Chenggang Qin <[email protected]>
In function filename__read_debuglink(), after the elf_begin() mmapped the dso file, the execution stream may goto "out_close". So, the elf_end() is skipped, and the munmap() cannot be executed.
While perf is executed for a long time, the files that are not munmapped will cost a large memory.
This patch fixed this bug.
Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by Chenggang Qin <[email protected]>
--- tools/perf/util/symbol-elf.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/util/symbol-elf.c +5 -5
@@ -471,27 +471,27 @@ int filename__read_debuglink(const char *filename, char *debuglink, ek =elf_kind (elf);if (ek !=ELF_K_ELF ) - goto out_close; + goto out_elf_end;if (gelf_getehdr (elf, &ehdr) ==NULL ) {pr_err ("%s: cannot get elf header.\n" , __func__); - goto out_close; + goto out_elf_end; } sec =elf_section_by_name (elf, &ehdr, &shdr,".gnu_debuglink" ,NULL );if (sec ==NULL ) - goto out_close; + goto out_elf_end; data =elf_getdata (sec,NULL );if (data ==NULL ) - goto out_close; + goto out_elf_end;/* the start of this section is a zero-terminated string */ strncpy (debuglink, data->d_buf, size); +out_elf_end:elf_end (elf); - out_close:close (fd); out:
Signature · 1 line
1.7.8.rc2.5.g815b