perf core: Fix a mmap and munmap mismatched bug
PATCH 1/3 perf core: Fix a mmap and munmap mismatched bug
From: root <[email protected]>
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 memory areas are mmapped is exist during the life of perf. This is a memory leak.
This patch fixed this bug.
Thanks.
--- 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
PATCH 2/3 perf core: Fix a mmap & munmap mismatches bug in dso__load
From: Chenggang Qin <[email protected]>
Some dsos' symsrc is neither syms_ss or runtime_ss. In this situation, the corresponding ELF file is opened and mmapped in symsrc__init(), but they will be not closed and munmapped in any place.
This bug can lead to mmap & munmap mismatched, the mmap areas will exist during the life of perf. We can think this is a memory leak.
This patch fixed the bug. symsrc__destroy() is called while the opened and mmaped ELF file has neither symtlb section nor dynsym section, and opdsec section.
Thanks.
--- tools/perf/util/symbol.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
tools/perf/util/symbol.c +2 -1
@@ -828,7 +828,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)if (syms_ss && runtime_ss)break ; - } + }else +symsrc__destroy (ss); }
Signature · 1 line
1.7.8.rc2.5.g815b
Re: [PATCH 2/3] perf core: Fix a mmap & munmap mismatches bug in dso__load
Quoted 11 lines · Chenggang Qin
From: Chenggang Qin <[email protected]>
Some dsos' symsrc is neither
syms_ssorruntime_ss. In this situation, the corresponding ELF file is opened and mmapped insymsrc__init(), but they will be not closed and munmapped in any place.
This bug can lead to mmap & munmap mismatched, the mmap areas will exist during the life of perf. We can think this is a memory leak.
This patch fixed the bug.symsrc__destroy()is called while the opened and mmaped ELF file has neither symtlb section nor dynsym section, and opdsec section.
Thanks.
Thanks,
Namhyung
PATCH 3/3 perf core: Fix a memory leak bug because symbol__delete is ignored
In reply to Chenggang QinFrom: Chenggang Qin <[email protected]>
In function symbols__fixup_duplicate(), while the duplicated symbols are found, only the rb_node are deleted. The symbol structures themself are ignored. Then, these memory areas are lost.
This patch fixed the bug.
Thanks.
--- tools/perf/util/symbol.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
tools/perf/util/symbol.c +2 -0
@@ -148,10 +148,12 @@ again:if (choose_best_symbol (curr, next) ==SYMBOL_A ) {rb_erase (&next->rb_node, symbols); +symbol__delete (next); goto again; }else { nd =rb_next (&curr->rb_node);rb_erase (&curr->rb_node, symbols); +symbol__delete (curr); } } }
Signature · 1 line
1.7.8.rc2.5.g815b
Re: [PATCH 3/3] perf core: Fix a memory leak bug because symbol__delete is ignored
Quoted 7 lines · Chenggang Qin
From: Chenggang Qin <[email protected]>
In function
symbols__fixup_duplicate(), while the duplicated symbols are found, only therb_nodeare deleted. The symbol structures themself are ignored. Then, these memory areas are lost.
This patch fixed the bug.
Thanks.
Thanks,
Namhyung
Hi Chenggang,
Quoted 9 lines · Chenggang Qin
From: root <[email protected]>
In function
filename__read_debuglink(), while the ELF file is opend and mmapped inelf_begin(), but if this file is considered to not be usable during the following code, we will goto the close(fd) directly. Theelf_end()is skipped. So, the mmaped ELF file cannot be munmapped. The memory areas are mmapped is exist during the life of perf. This is a memory leak.
This patch fixed this bug.
Thanks.
Thanks,
Namhyung