Strange crash caused by ~TString()

Hi. I have a macro that I’m using compiled using “.L macroName.cc++” and I’m encountering a strange crash at the end of running.

I’m using ROOT 5.22/00d, included with the CMSSW release I’m using.

The macro runs all the way to the end without issue, but when the last line of code is executed and the macro goes to exit, it sends an abort signal and exits with a stack trace.

I compiled the macro with debug symbols and generated a stack trace using GDB. It appears that the crash (actually a double free()) is occuring upon destruction of one of the TString objects I’ve allocated. Here’s the portion of the stack trace:

#0 0xffffe410 in __kernel_vsyscall ()
#1 0x00b6fdf0 in raise () from /lib/libc.so.6
#2 0x00b71701 in abort () from /lib/libc.so.6
#3 0x00ba828b in __libc_message () from /lib/libc.so.6
#4 0x00bb05a5 in _int_free () from /lib/libc.so.6
#5 0x00bb09e9 in free () from /lib/libc.so.6
#6 0xf6da5f41 in operator delete (ptr=0x0)
at …/…/…/…/libstdc+±v3/libsupc++/del_op.cc:49
#7 0xf6da5f9d in operator delete[] (ptr=0x998d318)
at …/…/…/…/libstdc+±v3/libsupc++/del_opv.cc:37
#8 0xf7a0dedb in TString::~TString() ()
from /amd/hepcode/nfs/hepcode/cmssw/cmssoft/cms/slc5_ia32_gcc434/lcg/root/5.22.00d-cms19/lib/libCore.so
#9 0xf59c24c6 in plotCorrected_2d ()
at /amd/lnxdata307/nfs/data37/cms/drell/ichepAnalysis/CMSSW_3_6_2/src/UserCode/Drell/V0Scripts2d/./plotCorrected_2d.cc:753

I haven’t used dynamic memory allocation for the objects. I do something like:

TString theString = “the string content”

rather than using new.

Has anybody seen this sort of thing before? It seems like it’d be a reference counting problem with one of the strings, but I can’t for the life of me figure out which one it is.

Thanks.

Okay, I’ve now done some further investigation.

There is one particular TString in my code that’s causing ~TString to fail. I don’t actually use the TString, so it’s fairly easy to track down what’s happening.

The TString is declared on the line after I declare a Double_t array using a dynamic size:

Double_t* theArray = new Double_t[arraySize];
TString* theString = new TString(“String Content”);

I was using the Double_t array as an error array to pass a histogram:

theHisto->SetError(theArray);

I’ve now switched my code to use a vector<Double_t> instead:

vector<Double_t> theArray;
TString* theString = new TString(“String Content”);

theHisto->SetError(&theArray[0]);

This works fine and does not cause the crash.

Is there something special about instantiating a TString after the declaration of a dynamic-sized Double_t array that could cause this problem?

This just looks like a coincidence because your code seems to be overwritten when you reach this point.
Could you provide a short running script or run your code under valgrind?

Rene