From 195732f074268e86055b6a774eb29ba7b03d8741 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 15 Mar 2017 15:29:35 -0400 Subject: [PATCH] Exception safety in: BatchCommands --- src/BatchCommands.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index a817854ca..930abdeca 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -481,10 +481,14 @@ bool BatchCommands::WriteMp3File( const wxString & Name, int bitrate ) bool rc; long prevBitRate = gPrefs->Read(wxT("/FileFormats/MP3Bitrate"), 128); gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), bitrate); + + auto cleanup = finally( [&] { + gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), prevBitRate); + gPrefs->Flush(); + } ); + // Use Mp3Stereo to control if export is to a stereo or mono file rc = mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime); - gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), prevBitRate); - gPrefs->Flush(); return rc; }