From 8a6351d9cdf8ce3ed464b7cede0ee4f020c3a319 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 20 Aug 2018 10:32:39 -0400 Subject: [PATCH] Guarantee cleanup of partial allocation on all error return paths... ... such as when allocating for capture channels fails after that for playback succeeds --- src/AudioIO.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 20ca2bb8e..0b92be8d4 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -2227,6 +2227,11 @@ bool AudioIO::AllocateBuffers( const TransportTracks &tracks, double t0, double t1, double sampleRate, bool scrubbing ) { + bool success = false; + auto cleanup = finally([&]{ + if (!success) StartStreamCleanup( false ); + }); + // // The (audio) stream has been opened successfully (assuming we tried // to open it). We now proceed to @@ -2337,7 +2342,6 @@ bool AudioIO::AllocateBuffers( // 100 samples, just give up. if(captureBufferSize < 100) { - StartStreamCleanup(); AudacityMessageBox(_("Out of memory!")); return false; } @@ -2373,13 +2377,13 @@ bool AudioIO::AllocateBuffers( (size_t)lrint(mRate * mPlaybackRingBufferSecs); if(playbackBufferSize < 100 || mPlaybackSamplesToCopy < 100) { - StartStreamCleanup(); AudacityMessageBox(_("Out of memory!")); return false; } } } while(!bDone); + success = true; return true; }