Skip to content

Instantly share code, notes, and snippets.

@wiso
Created December 15, 2014 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiso/f1eec4df4ee7a8bf4711 to your computer and use it in GitHub Desktop.
Save wiso/f1eec4df4ee7a8bf4711 to your computer and use it in GitHub Desktop.
THPoly problem
// compile with:
// g++ -std=c++11 example_THPoly_Attilafix2.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 <memory>
#include <TFile.h>
#include <TH2Poly.h>
#include <TROOT.h>
int main()
{
std::unique_ptr<TFile> f(TFile::Open("MVACalib_electron.weights.root"), "READ");
gROOT->cd();
TH2Poly* hPoly = dynamic_cast<TH2Poly*> (f->Get("hPoly"));
TH2Poly* m_hPoly = 0;
if (!m_hPoly) m_hPoly = (TH2Poly*) hPoly->Clone();
assert(m_hPoly);
f->Close();
delete m_hPoly;
}
// valdrind output
/*
==11444== Memcheck, a memory error detector
==11444== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==11444== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==11444== Command: ./a.out
==11444==
==11444== Invalid read of size 4
==11444== at 0x3C23804F9C: TList::Clear(char const*) (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C23806022: TList::~TList() (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C27BDED6C: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==11444== by 0x3C27BDEE08: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==11444== by 0x3C238062FC: TList::Delete(char const*) (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C25ACE8E1: TDirectoryFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==11444== by 0x3C25AC62A9: TFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==11444== by 0x4022A9: main (example_THPoly_Attilafix2.cxx:29)
==11444== Address 0x6d66e3c is 12 bytes inside a block of size 80 free'd
==11444== at 0x4A078DE: operator delete(void*) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11444== by 0x3C238062FC: TList::Delete(char const*) (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C23806022: TList::~TList() (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C23806088: TList::~TList() (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C27BDED38: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==11444== by 0x3C27BDEE08: TH2Poly::~TH2Poly() (in /usr/lib64/root/libHist.so.5.34)
==11444== by 0x3C238062FC: TList::Delete(char const*) (in /usr/lib64/root/libCore.so.5.34)
==11444== by 0x3C25ACE8E1: TDirectoryFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==11444== by 0x3C25AC62A9: TFile::Close(char const*) (in /usr/lib64/root/libRIO.so.5.34)
==11444== by 0x4022A9: main (example_THPoly_Attilafix2.cxx:29)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment