From cfe34647e1ea0898ad4ab23d4518e9fabf00c6d9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 7 Aug 2018 22:29:51 +0200 Subject: [PATCH] decoder/mpg123: use AtScopeExit() to call mpg123_delete() --- src/decoder/plugins/Mpg123DecoderPlugin.cxx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/decoder/plugins/Mpg123DecoderPlugin.cxx b/src/decoder/plugins/Mpg123DecoderPlugin.cxx index f8dbec88d..de002f29a 100644 --- a/src/decoder/plugins/Mpg123DecoderPlugin.cxx +++ b/src/decoder/plugins/Mpg123DecoderPlugin.cxx @@ -27,6 +27,7 @@ #include "tag/MixRamp.hxx" #include "fs/Path.hxx" #include "util/Domain.hxx" +#include "util/ScopeExit.hxx" #include "util/StringView.hxx" #include "Log.hxx" @@ -196,11 +197,11 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs) return; } + AtScopeExit(handle) { mpg123_delete(handle); }; + AudioFormat audio_format; - if (!mpd_mpg123_open(handle, path_fs.c_str(), audio_format)) { - mpg123_delete(handle); + if (!mpd_mpg123_open(handle, path_fs.c_str(), audio_format)) return; - } const off_t num_samples = mpg123_length(handle); @@ -272,10 +273,6 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs) cmd = DecoderCommand::NONE; } } while (cmd == DecoderCommand::NONE); - - /* cleanup */ - - mpg123_delete(handle); } static bool