-1

When I test run C++ programs with the option -fsanitize=address I see many locations point to an indirect leak. They are all initiated from libasan.so. The exact error shown below. I am not sure that I am responsible for this leak or not. I was able to fixed other direct leaks in my program.

Indirect leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f24e2b9c947 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10f947)
    #1 0x7f24e2517dc8 in __gnu_cxx::new_allocator<std::pair<char, int> >::allocate(unsigned long, void const*) /usr/include/c++/9/ext/new_allocator.h:114
    #2 0x7f24e250ed74 in std::allocator_traits<std::allocator<std::pair<char, int> > >::allocate(std::allocator<std::pair<char, int> >&, unsigned long) /usr/include/c++/9/bits/alloc_traits.h:444
    #3 0x7f24e24ff853 in std::_Vector_base<std::pair<char, int>, std::allocator<std::pair<char, int> > >::_M_allocate(unsigned long) /usr/include/c++/9/bits/stl_vector.h:343
    #4 0x7f24e24e8aa6 in std::_Vector_base<std::pair<char, int>, std::allocator<std::pair<char, int> > >::_M_create_storage(unsigned long) /usr/include/c++/9/bits/stl_vector.h:358
    #5 0x7f24e24d8ee8 in std::_Vector_base<std::pair<char, int>, std::allocator<std::pair<char, int> > >::_Vector_base(unsigned long, std::allocator<std::pair<char, int> > const&) /usr/include/c++/9/bits/stl_vector.h:302
    #6 0x7f24e24c9782 in std::vector<std::pair<char, int>, std::allocator<std::pair<char, int> > >::vector(std::vector<std::pair<char, int>, std::allocator<std::pair<char, int> > > const&) /usr/include/c++/9/bits/stl_vector.h:552
    #7 0x7f24e2579da6 in Hitbrief::Hitbrief(Hitbrief const&) /home/kzhou/coding/molbar/src/readcompass.h:21
    #8 0x7f24e2579e5b in std::pair<Hitbrief const, int>::pair<Hitbrief&&, 0ul>(std::tuple<Hitbrief&&>&, std::tuple<>&, std::_Index_tuple<0ul>, std::_Index_tuple<>) /usr/include/c++/9/tuple:1674
    #9 0x7f24e25798f0 in std::pair<Hitbrief const, int>::pair<Hitbrief&&>(std::piecewise_construct_t, std::tuple<Hitbrief&&>, std::tuple<>) /usr/include/c++/9/tuple:1663
    #10 0x7f24e2578f77 in void __gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<Hitbrief const, int> > >::construct<std::pair<Hitbrief const, int>, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::pair<Hitbrief const, int>*, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/ext/new_allocator.h:147
    #11 0x7f24e2577db5 in void std::allocator_traits<std::allocator<std::_Rb_tree_node<std::pair<Hitbrief const, int> > > >::construct<std::pair<Hitbrief const, int>, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::allocator<std::_Rb_tree_node<std::pair<Hitbrief const, int> > >&, std::pair<Hitbrief const, int>*, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/alloc_traits.h:484
    #12 0x7f24e2575199 in void std::_Rb_tree<Hitbrief, std::pair<Hitbrief const, int>, std::_Select1st<std::pair<Hitbrief const, int> >, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::_M_construct_node<std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::_Rb_tree_node<std::pair<Hitbrief const, int> >*, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/stl_tree.h:614
    #13 0x7f24e25714e9 in std::_Rb_tree_node<std::pair<Hitbrief const, int> >* std::_Rb_tree<Hitbrief, std::pair<Hitbrief const, int>, std::_Select1st<std::pair<Hitbrief const, int> >, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::_M_create_node<std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/stl_tree.h:631
    #14 0x7f24e256e7ae in std::_Rb_tree_iterator<std::pair<Hitbrief const, int> > std::_Rb_tree<Hitbrief, std::pair<Hitbrief const, int>, std::_Select1st<std::pair<Hitbrief const, int> >, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<Hitbrief const, int> >, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/stl_tree.h:2455
    #15 0x7f24e2568f82 in std::map<Hitbrief, int, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::operator[](Hitbrief&&) /usr/include/c++/9/bits/stl_map.h:518
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Kemin Zhou
  • 6,264
  • 2
  • 48
  • 56
  • 1
    `Hitbrief::Hitbrief(Hitbrief const&)` appears to be your code. Please make a [mre] – cigien Oct 01 '21 at 00:29
  • 1
    Indirect leaks are caused by direct leaks. You should have more reports above one you have posted. – 273K Oct 01 '21 at 00:29
  • Yes pretty long, good to know, I need to check to make sure I don't have any leaks. – Kemin Zhou Oct 01 '21 at 00:31
  • 1
    Once you fix direct leaks, indirect leaks go away or become new direct leaks. – 273K Oct 01 '21 at 00:33
  • Now I got zero direct leaks. Now got 7 indirect leaks only. I will check my code and try to get rid of them all. Thanks for the good feedback. I will experiment with minimal example. My code has more than 15k lines of code. – Kemin Zhou Oct 01 '21 at 00:38

1 Answers1

0

Even when all leaks are indirect, there is still memory leak in the source code. I was able to track down all leak and eliminate all indirect leaks. Thank for everyone feedback. In the past, eliminating direct leaks removed all the indirect leaks. This is my first experience, I think it is good to share with someone who experienced this situation for the first time.

Kemin Zhou
  • 6,264
  • 2
  • 48
  • 56