From 957b399e9088cf8e7dc885be2e60acad8b6fb5c6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 8 Sep 2016 20:41:44 +0200 Subject: [PATCH] decoder/Thread: call FlushChunk() using AtScopeExit() Be exception-safe. --- src/decoder/DecoderThread.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx index 89c222bdf..f497b8bfd 100644 --- a/src/decoder/DecoderThread.cxx +++ b/src/decoder/DecoderThread.cxx @@ -36,6 +36,7 @@ #include "util/Error.hxx" #include "util/RuntimeError.hxx" #include "util/Domain.hxx" +#include "util/ScopeExit.hxx" #include "thread/Name.hxx" #include "tag/ApeReplayGain.hxx" #include "Log.hxx" @@ -404,12 +405,14 @@ decoder_run_song(DecoderControl &dc, { const ScopeUnlock unlock(dc.mutex); + AtScopeExit(&decoder) { + /* flush the last chunk */ + if (decoder.chunk != nullptr) + decoder.FlushChunk(); + }; + success = DecoderUnlockedRunUri(decoder, uri, path_fs); - /* flush the last chunk */ - - if (decoder.chunk != nullptr) - decoder.FlushChunk(); } if (decoder.error.IsDefined()) {