diff --git a/src/xml/XMLWriter.cpp b/src/xml/XMLWriter.cpp index cc82cbed5..dd1904c02 100644 --- a/src/xml/XMLWriter.cpp +++ b/src/xml/XMLWriter.cpp @@ -302,10 +302,10 @@ XMLFileWriter::~XMLFileWriter() { // Don't let a destructor throw! GuardedCall< void >( [&] { - if (IsOpened()) { - // Was not committed + if (!mCommitted) { auto fileName = GetName(); - CloseWithoutEndingTags(); + if ( IsOpened() ) + CloseWithoutEndingTags(); ::wxRemoveFile( fileName ); } } ); @@ -340,6 +340,8 @@ void XMLFileWriter::Commit() throw FileException{ FileException::Cause::Rename, tempPath, mCaption, mOutputPath }; + + mCommitted = true; } void XMLFileWriter::CloseWithoutEndingTags() diff --git a/src/xml/XMLWriter.h b/src/xml/XMLWriter.h index 961277ef2..e8262d7b0 100644 --- a/src/xml/XMLWriter.h +++ b/src/xml/XMLWriter.h @@ -111,6 +111,8 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter { const bool mKeepBackup; wxFFile mBackupFile; + + bool mCommitted{ false }; }; ///