1

I recently ran valgrind tool dhat in a code and got the below results. It says deaths =none , seems to be a memory leak. But this is shown in unordered_map. I have enabled -g mode.

Please let me know if this is a issue in STL or issue in the code.

   ==27444== -------------------- 22 of 50 --------------------
==27444== max-live:    245,820 in 5 blocks
==27444== tot-alloc:   245,820 in 5 blocks (avg size 49164.00)
==27444== deaths:      none (none of these blocks were freed)
==27444== acc-ratios:  0.00 rd, 1.00 wr  (48 b-read, 246,108 b-written)
==27444==    at 0x4C28425: operator new(unsigned long) (vg_replace_malloc.c:333)
==27444==    by 0x6EAB0F0: __gnu_cxx::__pool<true>::_M_initialize() (in /usr/lib64/libstdc++.so.6.0.19)
==27444==    by 0x5A86D4: __gnu_cxx::__pool<true>::_M_initialize_once() (mt_allocator.h:329)
==27444==    by 0x5AF772: __gnu_cxx::__common_pool_base<__gnu_cxx::__pool, true>::_S_initialize() (mt_allocator.h:433)
==27444==    by 0x5410E1F: pthread_once (pthread_once.S:103)
==27444==    by 0x5879C2: __gthread_once(int*, void (*)()) (gthr-default.h:699)
==27444==    by 0x5AF4E6: __gnu_cxx::__common_pool_base<__gnu_cxx::__pool, true>::_S_initialize_once() (mt_allocator.h:445)
==27444==    by 0x6231F0: __gnu_cxx::__mt_alloc<std::__detail::_Hash_node_base*, __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, true> >::allocate(unsigned long, void const*) (mt_allocator.h:694)
==27444==    by 0x622294: std::_Hashtable<unsigned long, std::pair<unsigned long const, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*>, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> >, std::__detail::_Select1st, std::equal_to<unsigned long>, std::hash1<unsigned long, void>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_allocate_buckets(unsigned long) (hashtable.h:779)
==27444==    by 0x620399: std::_Hashtable<unsigned long, std::pair<unsigned long const, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*>, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> >, std::__detail::_Select1st, std::equal_to<unsigned long>, std::hash1<unsigned long, void>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_Hashtable(unsigned long, std::hash1<unsigned long, void> const&, std::__detail::_Mod_range_hashing const&, std::__detail::_Default_ranged_hash const&, std::equal_to<unsigned long> const&, std::__detail::_Select1st const&, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> > const&) (hashtable.h:831)
==27444==    by 0x61E6FA: std::_Hashtable<unsigned long, std::pair<unsigned long const, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*>, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> >, std::__detail::_Select1st, std::equal_to<unsigned long>, std::hash1<unsigned long, void>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_Hashtable(unsigned long, std::hash1<unsigned long, void> const&, std::equal_to<unsigned long> const&, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> > const&) (hashtable.h:397)
==27444==    by 0x61CB5C: std::unordered_map<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*, std::hash1<unsigned long, void>, std::equal_to<unsigned long>, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> > >::unordered_map(unsigned long, std::hash1<unsigned long, void> const&, std::equal_to<unsigned long> const&, __std_cxx::__mt_alloc<std::pair<unsigned long, __std_cxx::ExtKey_Map<std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >, unsigned long, __std_cxx::__mt_alloc<std::pair<unsigned long, std::unordered_map<int, unsigned long, std::hash<int>, std::equal_to<int>, __std_cxx::__mt_alloc<unsigned long> >*> > >*> > const&) (unordered_map.h:142)
==27444== 
Surya
  • 21
  • 4
  • Issue in the (user) code. If it were an STL issue, it would have been discovered long time ago. E.g. If you create an instance of an STL container in a class of yours and do not destroy the instances of your classes when not needed anymore, this can show up like this. – Andre Holzner Jan 25 '18 at 14:47
  • And which calls makes valgrind report this? What about memcheck resuts? – user7860670 Jan 25 '18 at 14:52
  • memcheck doesnot show any leak, but this is shown as still reachable, not as lost, may be bcus process has track of this memory. – Surya Jan 25 '18 at 14:57
  • Actually i tried memcheck first. but for long running programs i think it wont be showing leak (as lost) if it has track of these memory, but heap keeps increasing. This report can be obtained by valgrind --tool=exp-dhat – Surya Jan 25 '18 at 14:59
  • 1
    @AndreHolzner - here the backtrace stopped in unordered_map.h:142. Any idea how to get backtrace for more than 12 steps. i see that there is a limit of 12 steps in the report. – Surya Jan 25 '18 at 15:05
  • @Surya , good point about the depth of the reported call stack: https://stackoverflow.com/a/25300420/288875 says that the corresponding option is `--num-callers` . – Andre Holzner Jan 25 '18 at 20:02
  • Can you show some source code? In particular the code that controls the lifetime of your std::unordered_map. – Paul Floyd Jan 26 '18 at 14:34
  • @ Andre Holzner - --num-callers , helped as the unordered map was part of a static instance hence death is none. Thanks – Surya Jan 30 '18 at 04:17
  • @Paul Floyd - its part of a static variable. Its a huge project so it was difficult to have a code walkthrough – Surya Jan 30 '18 at 04:37

0 Answers0