diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 6b97e04797bc4..635f3e8725e5f 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -2119,7 +2119,6 @@ Int_t TFile::Recover() if (fWritable && !fFree) fFree = new TList; - TKey *key; Int_t nrecov = 0; nwheader = 1024; Int_t nread = nwheader; @@ -2171,14 +2170,16 @@ Int_t TFile::Recover() TClass *tclass = TClass::GetClass(classname); if (seekpdir == fSeekDir && tclass && !tclass->InheritsFrom(TFile::Class()) && strcmp(classname,"TBasket")) { - key = new TKey(this); + + TKey *key = new TKey(this); key->ReadKeyBuffer(bufread); if (!strcmp(key->GetName(),"StreamerInfo")) { fSeekInfo = seekkey; SafeDelete(fInfoCache); fNbytesInfo = nbytes; + delete key; } else { - AppendKey(key); + AppendKey(key); // ownership transferred nrecov++; SetBit(kRecovered); Info("Recover", "%s, recovered key %s:%s at address %lld",GetName(),key->GetClassName(),key->GetName(),idcur); diff --git a/tree/dataframe/src/RDFSnapshotHelpers.cxx b/tree/dataframe/src/RDFSnapshotHelpers.cxx index ce5c339a0511e..0079330a064ee 100644 --- a/tree/dataframe/src/RDFSnapshotHelpers.cxx +++ b/tree/dataframe/src/RDFSnapshotHelpers.cxx @@ -260,7 +260,8 @@ void EnsureValidSnapshotRNTupleOutput(const ROOT::RDF::RSnapshotOptions &opts, c if (!outFile || outFile->IsZombie()) throw std::invalid_argument("Snapshot: cannot open file \"" + fileName + "\" in update mode"); - auto *outNTuple = outFile->Get(ntupleName.c_str()); + std::unique_ptr uoNT{outFile->Get(ntupleName.c_str())}; + auto *outNTuple = uoNT.get(); if (outNTuple) { if (opts.fOverwriteIfExists) { @@ -534,6 +535,7 @@ void ROOT::Internal::RDF::UntypedSnapshotTTreeHelper::SetEmptyBranches(TTree *in void ROOT::Internal::RDF::UntypedSnapshotTTreeHelper::Initialize() { + delete fOutputFile.release(); // delete before create. reset does it the other way round fOutputFile.reset( TFile::Open(fFileName.c_str(), fOptions.fMode.c_str(), /*ftitle=*/"", ROOT::CompressionSettings(fOptions.fCompressionAlgorithm, fOptions.fCompressionLevel))); @@ -937,6 +939,8 @@ void ROOT::Internal::RDF::UntypedSnapshotRNTupleHelper::Initialize() writeOptions.SetEnablePageChecksums(fOptions.fEnablePageChecksums); writeOptions.SetEnableSamePageMerging(fOptions.fEnableSamePageMerging); + // Delete beforehand (.reset does it in inverse order, creates new and then deletes) + delete fOutputFile.release(); fOutputFile.reset(TFile::Open(fFileName.c_str(), fOptions.fMode.c_str())); if (!fOutputFile) throw std::runtime_error("Snapshot: could not create output file " + fFileName);