Memory check with Valgrind

Hello,

I’m trying to look for possible memory leaks in my code and I tried to use valgrind, but it gives enormous number of errors and it looks like most of them are due to ROOT libraries.

I compile my code with g++ and link against ROOT libraries with command:

g++  *.cpp -g -ansi -Wall `/home/zablocki/CMS/root/bin/root-config --cflags`    `/home/zablocki/CMS/root/bin/root-config --libs`

then I’m running valgrind:

valgrind --tool=memcheck --suppressions=$ROOTSYS/etc/valgrind-root.supp  --log-file=log --leak-check=full myexecutable

I wonder what I might do wrong. Here is example of common error:

[code]==6952== 69,828 bytes in 1,587 blocks are possibly lost in loss record 38,505 of 38,514
==6952==    at 0x402569A: operator new(unsigned int) (vg_replace_malloc.c:255)
==6952==    by 0x492E7DF: std::_Rb_tree<char const*, std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > >, std::_Select1st<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > >, NameMap::G__charptr_less, std::allocator<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > const&) (in /home/zablocki/CMS/root/lib/libCint.so)
==6952==    by 0x492EB91: std::_Rb_tree<char const*, std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > >, std::_Select1st<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > >, NameMap::G__charptr_less, std::allocator<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > > >::_M_insert_unique_(std::_Rb_tree_const_iterator<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > >, std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > const&) (in /home/zablocki/CMS/root/lib/libCint.so)
==6952==    by 0x493D07E: G__search_tagname (in /home/zablocki/CMS/root/lib/libCint.so)
==6952==    by 0x493D2D2: G__set_class_autoloading_table (in /home/zablocki/CMS/root/lib/libCint.so)
==6952==    by 0x4241A2E: TCint::LoadLibraryMap(char const*) (in /home/zablocki/CMS/root/lib/libCore.so)
==6952==    by 0x423E923: TCint::EnableAutoLoading() (in /home/zablocki/CMS/root/lib/libCore.so)
==6952==    by 0x415CB7A: TApplication::TApplication(char const*, int*, char**, void*, int) (in /home/zablocki/CMS/root/lib/libCore.so)
==6952==    by 0x415CD9A: TApplication::CreateApplication() (in /home/zablocki/CMS/root/lib/libCore.so)
==6952==    by 0x57B702C: TCanvas::Init() (in /home/zablocki/CMS/root/lib/libGpad.so)
==6952==    by 0x57B7645: TCanvas::Constructor(char const*, char const*, int) (in /home/zablocki/CMS/root/lib/libGpad.so)
==6952==    by 0x57B8018: TCanvas::TCanvas(char const*, char const*, int) (in /home/zablocki/CMS/root/lib/libGpad.so)[/code]

Maybe I’m missing to call some destructors? I have no idea.

I would appreciate some help with this topic.

Hi,

we will need to suppress those, too - they are intentional. I will post the proper valgrind suppression file shortly.

Cheers, Axel.

Was a proper valgrind suppression file ever posted? Many thanks!!!

Hi,

yes, to subversion :slight_smile: It’s it in the trunk of ROOT, in $ROOTSYS/etc/. I have also attached it here.

Cheers, Axel.
valgrind-root.supp.txt (5.36 KB)

Hi,

I’ve got a problem using this valgring suppression file.
Here is an error I get:

==18493== Memcheck, a memory error detector
==18493== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==18493== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==18493== Command: ../bin/HgcOnlineMon.exe -f /scratch/run000032.raw
==18493==
location should be "...", or should start with "fun:" or "obj:"
==18493== FATAL: in suppressions file "/afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.08/x86_64-slc6-gcc49-opt/root/etc/valgrind-root.supp" near line 25:
==18493==    location should be "...", or should start with "fun:" or "obj:"
==18493== exiting now

Try fixing the valgrind suppression file with

 sed '/match-leak-kinds:/d' $ROOTSYS/etc/valgrind-root.supp > ./valgrind-root-fixed.supp 

and then rerun valgrind using this ./valgrind-root-fixed.supp from your working directory.

Hi Andrey,
the issue is probably due to that version of valgrind being too old and not understanding parts of ROOT’s suppression file. lxplus7 has version 3.13 installed, that should work.

Please next time open a new thread instead of resurrecting one from 2010! :smiley: