From 180a45c8c752c01ee81b8f7ac6aaaf8053f57d0e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 16 Mar 2006 14:14:15 -0500 Subject: [PATCH] BUG: Do not leak the ofstream object in append mode. Just use an auto_ptr for both cases. --- Source/cmExportLibraryDependencies.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/cmExportLibraryDependencies.cxx b/Source/cmExportLibraryDependencies.cxx index 3f39920e4..7dab94073 100644 --- a/Source/cmExportLibraryDependencies.cxx +++ b/Source/cmExportLibraryDependencies.cxx @@ -57,21 +57,19 @@ void cmExportLibraryDependenciesCommand::FinalPass() } // Use copy-if-different if not appending. - std::ostream* foutPtr; - std::auto_ptr foutNew; + std::auto_ptr foutPtr; if(append) { - foutPtr = new std::ofstream(fname.c_str(), std::ios::app); + foutPtr.reset(new std::ofstream(fname.c_str(), std::ios::app)); } else { std::auto_ptr ap( new cmGeneratedFileStream(fname.c_str(), true)); ap->SetCopyIfDifferent(true); - foutNew = ap; - foutPtr = foutNew.get(); + foutPtr.reset(ap.release()); } - std::ostream& fout = *foutPtr; + std::ostream& fout = *foutPtr.get(); if (!fout) {