Hello guy !
In the same way as my previous thread. I got a potential leak using Valgrind using TFile::Open. I tried to reduce my code as much as possible. So here is the code:
#include <TApplication.h>
#include <Riostream.h>
#include <TLorentzVector.h>
#include <TTree.h>
#include <TLegend.h>
#include <TFile.h>
#include <TKey.h>
#include <TH1.h>
#include <TH2.h>
#include <TH3.h>
#include <TGraph.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TEntryList.h>
#include <TROOT.h>
#include <TClass.h>
using namespace std;
/*
* List all objects using patterns
*/
int main(int argc, char **argv)
{
TFile *f1 = TFile::Open("XXX.root");
f1->Close();
delete f1;
f1 = NULL;
TFile *f2 = TFile::Open("XXX.root");
f2->Close();
delete f2;
f2 = NULL;
return 0;
}
Using ROOT6 (git commit: 90db6c66e8d43f9f9654c66ecb8f6d6f74856fd1), I obtained the following message ONLY if I try to open more than ONE TFile using TFile::Open. :
[...]
==3810== 4,120 bytes in 1 blocks are definitely lost in loss record 5,470 of 5,878
==3810== at 0x4C3089F: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3810== by 0x5621DCB: TFile::GetStreamerInfoListImpl(bool) (TFile.cxx:1334)
==3810== by 0x56221FA: TFile::ReadStreamerInfo() (TFile.cxx:3505)
==3810== by 0x5629EBA: TFile::Init(bool) (TFile.cxx:867)
==3810== by 0x562B4A7: TFile::TFile(char const*, char const*, char const*, int) (TFile.cxx:521)
==3810== by 0x562F141: TFile::Open(char const*, char const*, char const*, int, int) (TFile.cxx:4134)
==3810== by 0x108AFC: main (LsRoot.C:39)
==3810==
==3810== LEAK SUMMARY:
==3810== definitely lost: 4,304 bytes in 2 blocks
==3810== indirectly lost: 0 bytes in 0 blocks
==3810== possibly lost: 5,152 bytes in 44 blocks
==3810== still reachable: 31,037,868 bytes in 46,390 blocks
==3810== of which reachable via heuristic:
==3810== newarray : 3,032 bytes in 9 blocks
==3810== multipleinheritance: 928 bytes in 2 blocks
==3810== suppressed: 127,668 bytes in 1,289 blocks
==3810== Reachable blocks (those to which a pointer was found) are not shown.
==3810== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3810==
==3810== For counts of detected and suppressed errors, rerun with: -v
==3810== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 674 from 341)
I have no problem to delete those objects, but I guess that might a minor source issue at low level ?
On the other hand I tried to run the same code with ROOT 5.34/17 and I obtained the following message :
==25911==
==25911== HEAP SUMMARY:
==25911== in use at exit: 4,797,613 bytes in 58,494 blocks
==25911== total heap usage: 155,199 allocs, 96,705 frees, 10,884,971 bytes allocated
==25911==
==25911== 34 bytes in 1 blocks are possibly lost in loss record 20,980 of 41,005
==25911== at 0x4C295FC: operator new(unsigned long) (vg_replace_malloc.c:298)
==25911== by 0x9E1EC78: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (new_allocator.h:104)
==25911== by 0x54AB4F4: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCore.so)
==25911== by 0x9E20A25: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (basic_string.h:1743)
==25911== by 0x5C41CF7: G__add_setup_func (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5CAE820: G__pragma (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5C7FF19: G__exec_statement (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5C4AD11: G__loadfile (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5C4B599: G__include_file (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5C85709: G__exec_statement (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5CD74CD: G__define_struct (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911== by 0x5C83FAB: G__exec_statement (in /afs/cern.ch/work/m/meyerma/Opt/root-5.34.36/lib/root/libCint.so)
==25911==
==25911== LEAK SUMMARY:
==25911== definitely lost: 0 bytes in 0 blocks
==25911== indirectly lost: 0 bytes in 0 blocks
==25911== possibly lost: 34 bytes in 1 blocks
==25911== still reachable: 3,460,356 bytes in 43,721 blocks
==25911== suppressed: 1,337,223 bytes in 14,772 blocks
==25911== Reachable blocks (those to which a pointer was found) are not shown.
==25911== To see them, rerun with: --leak-check=full --show-reachable=yes
==25911==
==25911== For counts of detected and suppressed errors, rerun with: -v
==25911== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 930 from 119)