TPad::GetCanvas pointing to deleted TCanvas

Hi everyone,

Just a quick question about the following: in the macro below I end up with a pad pointing to a deleted canvas. This results in a segfault when you delete the pad. Am I doing something I should not be doing or is this a bug?

root [0] TCanvas* c = new TCanvas(“c”,“c”)
root [1] TPad* p = new TPad(“p”,“p”,0,0,1,1)
root [2] c
(class TCanvas*)0x4c31600
root [3] delete c
root [4] p->GetCanvas()
(const class TCanvas*)0x4c31600


When you delete the canvas, the pad in the canvas is also deleted.
Your pointer p points now to a deleted object.


just adding a few lines to show that this is a real problem (which is what Jeroen contacted me about):

TCanvas* c=new TCanvas(); TPad* p=new TPad(); delete c; p->Draw(); will create a segv because TPad::Draw accesses p’s mother though c is already dead. Note there is no interaction between p and c, so it’s a bit surprising to see this fail. I think setting fMother only once the pad is drawn (and thus added to fMother’s list of primitives) is less surprising.