why does this seg fault?

From: Mike Williams <williams_at_ernest.phys.cmu.edu>
Date: Thu, 20 Apr 2006 11:59:59 -0400 (EDT)


i've written a small example to illustrate a problem i found. i've attached several files:

HistoMaker.h: Class HistoMaker definition file. LinkDef.h: LinkDef i'm using

macro.C:      An example macro
test.cc:      A compilable version of macro (without the plotting)

HistoMaker is a simple class with a function that returns a vector<TH1F*> of filled histos (it also allocates memory for the histos). if i call it once everything is ok. to avoid a memory leak, before i call it again i delete the histos i got the previous call (this is done in macro.C).

the output i get when i run macro() is:

Iteration: 0
Ready to build hGaus_0...
Build successfull.
Ready to build hGaus_1...
Build successfull.
Ready to build hGaus_2...
Build successfull.
Ready to build hGaus_3...
Build successfull.

deleted hGaus_0
deleted hGaus_1
deleted hGaus_2
deleted hGaus_3

Iteration: 1
Ready to build hGaus_0...

if i comment out the delete histos[h] line, it runs the entire way through without seg faulting...but, of course, i get warning messages about replacing hGaus_0, etc., possible memory leak...

i'm not sure what's wrong here...am i just missing something or is this a bug?

also, test.cc is basically macro.C without the plotting, and it runs with no errors when compiled.


mike williams

Received on Thu Apr 20 2006 - 18:00:17 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:58 MET