Skip to content

Instantly share code, notes, and snippets.

@wiso
Last active August 29, 2015 14:11
Show Gist options
  • Save wiso/147ae6ac68126dfeaffc to your computer and use it in GitHub Desktop.
Save wiso/147ae6ac68126dfeaffc to your computer and use it in GitHub Desktop.
THPoly problem
// compile with:
// g++ example_THPoly.cxx -O0 -g `root-config --cflags` `root-config --libs`
// first download the file:
// wget http://atlas.web.cern.ch/Atlas/GROUPS/DATABASE/GroupData/egammaMVACalib/v1/MVACalib_electron.weights.root
// run with valgrind
// valgrind --tool=memcheck --suppressions=`root-config --etcdir`/valgrind-root.supp ./a.out
#include <cassert>
#include <TFile.h>
#include <TH2Poly.h>
int main()
{
TH2Poly* m_hPoly = 0;
TFile* f = TFile::Open("MVACalib_electron.weights.root ");
TH2Poly* hPoly = dynamic_cast<TH2Poly*> (f->Get("hPoly"));
if (!m_hPoly) m_hPoly = (TH2Poly*) hPoly->Clone();
m_hPoly->SetDirectory(0);
assert(m_hPoly);
f->Close();
delete f;
delete m_hPoly;
}
// valdrind output
/*
==6291== Memcheck, a memory error detector
==6291== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==6291== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==6291== Command: ./a.out
==6291==
==6291== Invalid read of size 4
==6291== at 0x3C23804F9C: TList::Clear(char const*) (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C23806022: TList::~TList() (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C27BDED6C: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==6291== by 0x3C27BDEE08: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==6291== by 0x3C238062FC: TList::Delete(char const*) (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C25ACE8E1: TDirectoryFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==6291== by 0x3C25AC62A9: TFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==6291== by 0x400B9A: main (example_THPoly.cxx:26)
==6291== Address 0x6fca64c is 12 bytes inside a block of size 80 free'd
==6291== at 0x4A078DE: operator delete(void*) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6291== by 0x3C238062FC: TList::Delete(char const*) (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C23806022: TList::~TList() (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C23806088: TList::~TList() (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C27BDED38: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==6291== by 0x3C27BDEE08: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==6291== by 0x3C238062FC: TList::Delete(char const*) (in /usr/lib64/root/libCore.so.5.34)
==6291== by 0x3C25ACE8E1: TDirectoryFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==6291== by 0x3C25AC62A9: TFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==6291== by 0x400B9A: main (example_THPoly.cxx:26)
==6291==
==6291==
==6291== HEAP SUMMARY:
==6291== in use at exit: 4,703,991 bytes in 54,084 blocks
==6291== total heap usage: 170,141 allocs, 116,057 frees, 11,528,099 bytes allocated
==6291==
==6291== LEAK SUMMARY:
==6291== definitely lost: 1,128 bytes in 1 blocks
==6291== indirectly lost: 130,378 bytes in 1,733 blocks
==6291== possibly lost: 0 bytes in 0 blocks
==6291== still reachable: 3,247,712 bytes in 36,789 blocks
==6291== suppressed: 1,324,773 bytes in 15,561 blocks
==6291== Rerun with --leak-check=full to see details of leaked memory
==6291==
==6291== For counts of detected and suppressed errors, rerun with: -v
==6291== ERROR SUMMARY: 1116 errors from 1 contexts (suppressed: 1580 from 81)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment