diff --git a/src/decoder/plugins/AudiofileDecoderPlugin.cxx b/src/decoder/plugins/AudiofileDecoderPlugin.cxx index 17abdf1b6..b1b97b272 100644 --- a/src/decoder/plugins/AudiofileDecoderPlugin.cxx +++ b/src/decoder/plugins/AudiofileDecoderPlugin.cxx @@ -23,6 +23,7 @@ #include "input/InputStream.hxx" #include "CheckAudioFormat.hxx" #include "tag/TagHandler.hxx" +#include "util/ScopeExit.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include "Log.hxx" @@ -195,6 +196,8 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is) if (fh == AF_NULL_FILEHANDLE) return; + AtScopeExit(fh) { afCloseFile(fh); }; + Error error; AudioFormat audio_format; if (!audio_format_init_checked(audio_format, @@ -203,7 +206,6 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is) afGetVirtualChannels(fh, AF_DEFAULT_TRACK), error)) { LogError(error); - afCloseFile(fh); return; } @@ -240,8 +242,6 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is) cmd = DecoderCommand::NONE; } } while (cmd == DecoderCommand::NONE); - - afCloseFile(fh); } gcc_pure