Memory Access Conflict

The following code fragment produces a memory access conflict at seemingly random points during the loop, depending on which testfile is used. It always occurs during the Smooth function and the error is “Attempted to read or write protected memory”. If the line tree->GetEntry(loop) is removed, then there are no errors. Any help would be appreciated.

TFile* file = new TFile(“testfile.root”);
TTree* tree = (TTree*)file->Get(“tree”);
MyClass* car = new MyClass;
tree->SetBranchAddress(“branch”, &car);

TH1F* smoothhistogram = NULL;
TF1 func(“func”, “cos(x)^2”, 0, 100);
Int_t numberOfEntries = tree->GetEntries();

for(Int_t loop = 0; loop < numberOfEntries; loop++){


smoothhistogram = new TH1F("histogram", "", 50, 0, 50);

    smoothhistogram->FillRandom("func", 200);


delete smoothhistogram;


There is nothing noticeably wrong in your code. Please either try valgrind ( or send us a way to reproduce your problem.


Attached is a simplified version of the class I used, as well as the main function. This produces the same error as described above. Thanks in advance for the help.
MyClass.h (869 Bytes)
main.cpp (1.76 KB)
MyClass.cpp (1.97 KB)


The problem is that you do not initialize the pointer data member of your class in the default constructor. Hence the value of those data member are random and when the ROOT I/O uses them, the result is also random (hence the core dump). So use something like:MyClass::MyClass() { //Default Constructor fNumberOfPoints = 0; fProfile1 = 0; fProfile2 = 0; etc..

seems, ndunn didn’t try valgrind which is a perfect tool for such kind of problems.

Thank you very much for the help. As for valgrind, I don’t have access to a Linux box where I work. Is there something similar I could use that runs on Windows XP?

I followed your suggestion and initialized all of the pointers to 0 in my default constructor. However, I’m still experiencing the same error. I attached the updated version of MyClass.
MyClass.cpp (2.2 KB)

You DO NOT SET all your pointers to null. In the default constructor,add:

fProfile1 =0; fProfile2 =0; fProfile3 =0; fProfile4 =0; fProfile5 =0; fProfile6 =0; fProfile7 =0; fProfile8 =0; fProfile9 =0; fProfile10 =0; fProfile11 =0; fProfile12 =0; fProfile13 =0;

In the version of MyClass in my most recent post, the constructor reads

//Default Constructor
fNumberOfPoints = 0;
fProfile1 = 0;
fProfile2 = 0;
fProfile3 = 0;
fProfile4 = 0;
fProfile5 = 0;
fProfile6 = 0;
fProfile7 = 0;
fProfile8 = 0;
fProfile9 = 0;
fProfile10 = 0;
fProfile11 = 0;
fProfile12 = 0;
fProfile13 = 0;

Using that code I experience the same error.

I see the problem now. Nothing to do with Trees but with TH1::Smooth.
We will investigate the problem next week.
Thanks for reporting.



I have a patch for this which I’m sending to you and Philippe directly
for testing and verification.

– Paul Russo

Thanks for having reported this problem and thanks to Paul for fixing it.
Fix now in CVS.