diff options
author | Max Kellermann <max@musicpd.org> | 2018-07-07 13:27:26 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-07-07 13:27:26 +0200 |
commit | 45cccbce59bf47e4fe659e94bc5ef42b64f4bb27 (patch) | |
tree | 0b721a837c5d8eeeaf3af581b066998a8ceb25f5 /src/decoder | |
parent | 479de9c7cbca284d8ef18602ec5e684162a1e007 (diff) |
decoder/sndfile: use AtScopeExit()
Fixes memory leaks.
Diffstat (limited to 'src/decoder')
-rw-r--r-- | src/decoder/plugins/SndfileDecoderPlugin.cxx | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/decoder/plugins/SndfileDecoderPlugin.cxx b/src/decoder/plugins/SndfileDecoderPlugin.cxx index 49ce322c9..7c20f1566 100644 --- a/src/decoder/plugins/SndfileDecoderPlugin.cxx +++ b/src/decoder/plugins/SndfileDecoderPlugin.cxx @@ -24,6 +24,7 @@ #include "CheckAudioFormat.hxx" #include "tag/Handler.hxx" #include "util/Domain.hxx" +#include "util/ScopeExit.hxx" #include "Log.hxx" #include <exception> @@ -208,6 +209,8 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is) return; } + AtScopeExit(sf) { sf_close(sf); }; + const auto audio_format = CheckAudioFormat(info); client.Ready(audio_format, info.seekable, sndfile_duration(info)); @@ -239,8 +242,6 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is) cmd = DecoderCommand::NONE; } } while (cmd == DecoderCommand::NONE); - - sf_close(sf); } static void @@ -277,8 +278,9 @@ sndfile_scan_stream(InputStream &is, TagHandler &handler) noexcept if (sf == nullptr) return false; + AtScopeExit(sf) { sf_close(sf); }; + if (!audio_valid_sample_rate(info.samplerate)) { - sf_close(sf); FormatWarning(sndfile_domain, "Invalid sample rate in %s", is.GetURI()); return false; @@ -289,8 +291,6 @@ sndfile_scan_stream(InputStream &is, TagHandler &handler) noexcept for (auto i : sndfile_tags) sndfile_handle_tag(sf, i.str, i.tag, handler); - sf_close(sf); - return true; } |