Skip to content

Commit c9f787b

Browse files
committed
[core] Make TDirectory::Append tolerant to identical objects.
When calling TDirectory::Append(obj, replace=true), and obj is already in the directory, don't issue a warning. Proceed to clear the list of any duplicates, issuing a warning for each. This will enable workflows such as: auto h = new TH1D(...); directory->Append(h, true); After this change, the above lines work both with implicit object ownership off and on.
1 parent c6512a3 commit c9f787b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/base/src/TDirectory.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ void TDirectory::Append(TObject *obj, Bool_t replace /* = kFALSE */)
207207
if (replace && obj->GetName() && obj->GetName()[0]) {
208208
TObject *old;
209209
while (nullptr != (old = GetList()->FindObject(obj->GetName()))) {
210-
Warning("Append","Replacing existing %s: %s (Potential memory leak).",
211-
obj->IsA()->GetName(),obj->GetName());
210+
if (obj != old) {
211+
Warning("Append","Replacing existing %s: %s (Potential memory leak).",
212+
obj->IsA()->GetName(),obj->GetName());
213+
}
212214
ROOT::DirAutoAdd_t func = old->IsA()->GetDirectoryAutoAdd();
213215
if (func) {
214216
func(old,nullptr);

0 commit comments

Comments
 (0)