decoder/sndfile: use AtScopeExit()

Fixes memory leaks.
This commit is contained in:
Max Kellermann 2018-07-07 13:27:26 +02:00
parent 479de9c7cb
commit 45cccbce59
1 changed files with 5 additions and 5 deletions

View File

@ -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;
}