diff --git a/io/io/src/TFileMerger.cxx b/io/io/src/TFileMerger.cxx
index e1f20451782329a71f8353e297cb9c88f0d0b7f6..33b0a323f9b5f506d670d729a818523e8b4c7d2f 100644
--- a/io/io/src/TFileMerger.cxx
+++ b/io/io/src/TFileMerger.cxx
@@ -458,7 +458,8 @@ Bool_t TFileMerger::MergeOne(TDirectory *target, TList *sourcelist, Int_t type,
       if (!obj && key) {
          obj = key->ReadObj();
          ownobj = kTRUE;
-      } else if (obj && info.fIsFirst && current_sourcedir != target) {
+      } else if (obj && info.fIsFirst && current_sourcedir != target
+                 && !cl->InheritsFrom( TDirectory::Class() )) {
          R__ASSERT(cl->IsTObject());
          TDirectory::TContext ctxt(current_sourcedir);
          obj = obj->Clone();
@@ -682,7 +683,7 @@ Bool_t TFileMerger::MergeOne(TDirectory *target, TList *sourcelist, Int_t type,
       // and we are in incremental mode (because it will be reused
       // and has not been written to disk (for performance reason).
       // coverity[var_deref_model] the IsA()->InheritsFrom guarantees that the dynamic_cast will succeed.
-      if (!(type & kIncremental) || dirobj->GetFile() != target) {
+      if (ownobj && (!(type & kIncremental) || dirobj->GetFile() != target)) {
          dirobj->ResetBit(kMustCleanup);
          delete dirobj;
       }