Commit 45cccbce authored by Max Kellermann's avatar Max Kellermann

decoder/sndfile: use AtScopeExit()

Fixes memory leaks.
parent 479de9c7
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/ScopeExit.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <exception> #include <exception>
...@@ -208,6 +209,8 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is) ...@@ -208,6 +209,8 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is)
return; return;
} }
AtScopeExit(sf) { sf_close(sf); };
const auto audio_format = CheckAudioFormat(info); const auto audio_format = CheckAudioFormat(info);
client.Ready(audio_format, info.seekable, sndfile_duration(info)); client.Ready(audio_format, info.seekable, sndfile_duration(info));
...@@ -239,8 +242,6 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is) ...@@ -239,8 +242,6 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is)
cmd = DecoderCommand::NONE; cmd = DecoderCommand::NONE;
} }
} while (cmd == DecoderCommand::NONE); } while (cmd == DecoderCommand::NONE);
sf_close(sf);
} }
static void static void
...@@ -277,8 +278,9 @@ sndfile_scan_stream(InputStream &is, TagHandler &handler) noexcept ...@@ -277,8 +278,9 @@ sndfile_scan_stream(InputStream &is, TagHandler &handler) noexcept
if (sf == nullptr) if (sf == nullptr)
return false; return false;
AtScopeExit(sf) { sf_close(sf); };
if (!audio_valid_sample_rate(info.samplerate)) { if (!audio_valid_sample_rate(info.samplerate)) {
sf_close(sf);
FormatWarning(sndfile_domain, FormatWarning(sndfile_domain,
"Invalid sample rate in %s", is.GetURI()); "Invalid sample rate in %s", is.GetURI());
return false; return false;
...@@ -289,8 +291,6 @@ sndfile_scan_stream(InputStream &is, TagHandler &handler) noexcept ...@@ -289,8 +291,6 @@ sndfile_scan_stream(InputStream &is, TagHandler &handler) noexcept
for (auto i : sndfile_tags) for (auto i : sndfile_tags)
sndfile_handle_tag(sf, i.str, i.tag, handler); sndfile_handle_tag(sf, i.str, i.tag, handler);
sf_close(sf);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment