From e2bc63217aad3934c0eea4852022db2949e5a1a1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 31 Dec 2015 13:31:12 +0100 Subject: [PATCH] decoder/Thread: decoder_input_stream_open() returns std::unique_ptr Fixes memory leak after InputStream::Check() failure. --- src/decoder/DecoderThread.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx index 173ea788c..175f7a905 100644 --- a/src/decoder/DecoderThread.cxx +++ b/src/decoder/DecoderThread.cxx @@ -55,12 +55,13 @@ static constexpr Domain decoder_thread_domain("decoder_thread"); * @return an InputStream on success or if #DecoderCommand::STOP is * received, nullptr on error */ -static InputStream * +static std::unique_ptr decoder_input_stream_open(DecoderControl &dc, const char *uri) { Error error; - InputStream *is = InputStream::Open(uri, dc.mutex, dc.cond, error); + std::unique_ptr is(InputStream::Open(uri, dc.mutex, + dc.cond, error)); if (is == nullptr) { if (error.IsDefined()) LogError(error); @@ -89,12 +90,13 @@ decoder_input_stream_open(DecoderControl &dc, const char *uri) return is; } -static InputStream * +static std::unique_ptr decoder_input_stream_open(DecoderControl &dc, Path path) { Error error; - InputStream *is = OpenLocalInputStream(path, dc.mutex, dc.cond, error); + std::unique_ptr is(OpenLocalInputStream(path, dc.mutex, + dc.cond, error)); if (is == nullptr) { LogError(error); return nullptr; @@ -261,7 +263,8 @@ decoder_run_stream(Decoder &decoder, const char *uri) { DecoderControl &dc = decoder.dc; - std::unique_ptr input_stream(decoder_input_stream_open(dc, uri)); + std::unique_ptr input_stream = + decoder_input_stream_open(dc, uri); if (input_stream == nullptr) return false; @@ -307,7 +310,8 @@ TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix, const ScopeLock protect(dc.mutex); return decoder_file_decode(plugin, decoder, path_fs); } else if (plugin.stream_decode != nullptr) { - std::unique_ptr input_stream(decoder_input_stream_open(dc, path_fs)); + std::unique_ptr input_stream = + decoder_input_stream_open(dc, path_fs); if (input_stream == nullptr) return false;