BUG: Do not leak the ofstream object in append mode. Just use an auto_ptr for both cases.

This commit is contained in:
Brad King 2006-03-16 14:14:15 -05:00
parent 3b43c29a30
commit 180a45c8c7
1 changed files with 4 additions and 6 deletions

View File

@ -57,21 +57,19 @@ void cmExportLibraryDependenciesCommand::FinalPass()
} }
// Use copy-if-different if not appending. // Use copy-if-different if not appending.
std::ostream* foutPtr; std::auto_ptr<std::ofstream> foutPtr;
std::auto_ptr<cmGeneratedFileStream> foutNew;
if(append) if(append)
{ {
foutPtr = new std::ofstream(fname.c_str(), std::ios::app); foutPtr.reset(new std::ofstream(fname.c_str(), std::ios::app));
} }
else else
{ {
std::auto_ptr<cmGeneratedFileStream> ap( std::auto_ptr<cmGeneratedFileStream> ap(
new cmGeneratedFileStream(fname.c_str(), true)); new cmGeneratedFileStream(fname.c_str(), true));
ap->SetCopyIfDifferent(true); ap->SetCopyIfDifferent(true);
foutNew = ap; foutPtr.reset(ap.release());
foutPtr = foutNew.get();
} }
std::ostream& fout = *foutPtr; std::ostream& fout = *foutPtr.get();
if (!fout) if (!fout)
{ {