@@ -123,7 +123,12 @@ TCutG::TCutG(const char *name, Int_t n)
123123 fObjectX = nullptr ;
124124 fObjectY = nullptr ;
125125 SetName (name);
126- delete gROOT ->GetListOfSpecials ()->FindObject (name);
126+ auto obj = gROOT ->GetListOfSpecials ()->FindObject (name);
127+ if (obj) {
128+ Warning (" TCutG" ," Replacing existing %s: %s (Potential memory leak)." ,
129+ obj->IsA ()->GetName (),obj->GetName ());
130+ delete obj;
131+ }
127132 gROOT ->GetListOfSpecials ()->Add (this );
128133
129134 // Take name of cut variables from pad title if title contains ":"
@@ -164,7 +169,12 @@ TCutG::TCutG(const char *name, Int_t n, const Float_t *x, const Float_t *y)
164169 fObjectX = nullptr ;
165170 fObjectY = nullptr ;
166171 SetName (name);
167- delete gROOT ->GetListOfSpecials ()->FindObject (name);
172+ auto obj = gROOT ->GetListOfSpecials ()->FindObject (name);
173+ if (obj) {
174+ Warning (" TCutG" ," Replacing existing %s: %s (Potential memory leak)." ,
175+ obj->IsA ()->GetName (),obj->GetName ());
176+ delete obj;
177+ }
168178 gROOT ->GetListOfSpecials ()->Add (this );
169179
170180 // Take name of cut variables from pad title if title contains ":"
@@ -205,7 +215,12 @@ TCutG::TCutG(const char *name, Int_t n, const Double_t *x, const Double_t *y)
205215 fObjectX = nullptr ;
206216 fObjectY = nullptr ;
207217 SetName (name);
208- delete gROOT ->GetListOfSpecials ()->FindObject (name);
218+ auto obj = gROOT ->GetListOfSpecials ()->FindObject (name);
219+ if (obj) {
220+ Warning (" TCutG" ," Replacing existing %s: %s (Potential memory leak)." ,
221+ obj->IsA ()->GetName (),obj->GetName ());
222+ delete obj;
223+ }
209224 gROOT ->GetListOfSpecials ()->Add (this );
210225
211226 // Take name of cut variables from pad title if title contains ":"
0 commit comments