https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105240
Bug ID: 105240 Summary: backtrace_pcinfo leaks memory Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libbacktrace Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org CC: ian at gcc dot gnu.org Target Milestone: --- I'm seeing lots of leaked memory for simple uses of libbacktrace: $ valgrind --leak-check=full ./stacktrace ==297621== Memcheck, a memory error detector ==297621== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==297621== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==297621== Command: ./stacktrace ==297621== ==297621== ==297621== HEAP SUMMARY: ==297621== in use at exit: 699,881 bytes in 1,134 blocks ==297621== total heap usage: 2,469 allocs, 1,335 frees, 1,473,361 bytes allocated ==297621== ==297621== 2,286 bytes in 53 blocks are definitely lost in loss record 12 of 20 ==297621== at 0x484086F: malloc (vg_replace_malloc.c:381) ==297621== by 0x4113F5: __glibcxx_backtrace_alloc (alloc.c:57) ==297621== by 0x413672: read_lnct (dwarf.c:2543) ==297621== by 0x413672: read_line_header_format_entries (dwarf.c:2618) ==297621== by 0x415286: read_line_header (dwarf.c:2712) ==297621== by 0x415286: read_line_info (dwarf.c:2965) ==297621== by 0x415286: dwarf_lookup_pc (dwarf.c:3747) ==297621== by 0x4162B0: dwarf_fileline (dwarf.c:3935) ==297621== by 0x405B95: std::stacktrace_entry::_M_get_info(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int*) const (stacktrace:186) ==297621== by 0x405885: std::stacktrace_entry::source_line() const (stacktrace:129) ==297621== by 0x404B08: test_assign() (stacktrace.cc:132) ==297621== by 0x40554E: main (stacktrace.cc:212) ==297621== ==297621== 46,055 bytes in 1 blocks are possibly lost in loss record 17 of 20 ==297621== at 0x484086F: malloc (vg_replace_malloc.c:381) ==297621== by 0x4113F5: __glibcxx_backtrace_alloc (alloc.c:57) ==297621== by 0x4112EA: __glibcxx_backtrace_get_view (read.c:68) ==297621== by 0x410CC3: elf_add.constprop.0 (elf.c:4381) ==297621== by 0x4111E3: __glibcxx_backtrace_initialize (elf.c:4877) ==297621== by 0x40BC47: fileline_initialize (fileline.c:261) ==297621== by 0x40BCE5: __glibcxx_backtrace_pcinfo (fileline.c:295) ==297621== by 0x405B95: std::stacktrace_entry::_M_get_info(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int*) const (stacktrace:186) ==297621== by 0x405885: std::stacktrace_entry::source_line() const (stacktrace:129) ==297621== by 0x404B08: test_assign() (stacktrace.cc:132) ==297621== by 0x40554E: main (stacktrace.cc:212) ==297621== ==297621== LEAK SUMMARY: ==297621== definitely lost: 2,286 bytes in 53 blocks ==297621== indirectly lost: 0 bytes in 0 blocks ==297621== possibly lost: 46,055 bytes in 1 blocks ==297621== still reachable: 651,540 bytes in 1,080 blocks ==297621== suppressed: 0 bytes in 0 blocks ==297621== Reachable blocks (those to which a pointer was found) are not shown. ==297621== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==297621== ==297621== For lists of detected and suppressed errors, rerun with: -s ==297621== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) This only happens when libbacktrace uses malloc instead of mmap.