From 1a8c96a3f0a4ba12866980acd7a6ff76fd47bdaf Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 18 Nov 2016 12:22:41 +0100
Subject: [PATCH] decoder/mpcdec: use AtScopeExit()

---
 src/decoder/plugins/MpcdecDecoderPlugin.cxx | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/decoder/plugins/MpcdecDecoderPlugin.cxx b/src/decoder/plugins/MpcdecDecoderPlugin.cxx
index 2922daca9..a5f58c288 100644
--- a/src/decoder/plugins/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/plugins/MpcdecDecoderPlugin.cxx
@@ -27,6 +27,7 @@
 #include "util/Domain.hxx"
 #include "util/Macros.hxx"
 #include "util/Clamp.hxx"
+#include "util/ScopeExit.hxx"
 #include "Log.hxx"
 
 #include <mpc/mpcdec.h>
@@ -158,6 +159,8 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
 		return;
 	}
 
+	AtScopeExit(demux) { mpc_demux_exit(demux); };
+
 	mpc_streaminfo info;
 	mpc_demux_get_info(demux, &info);
 
@@ -217,8 +220,6 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
 					chunk, ret * sizeof(chunk[0]),
 					bit_rate);
 	} while (cmd != DecoderCommand::STOP);
-
-	mpc_demux_exit(demux);
 }
 
 static SignedSongTime
@@ -238,9 +239,10 @@ mpcdec_get_file_duration(InputStream &is)
 	if (demux == nullptr)
 		return SignedSongTime::Negative();
 
+	AtScopeExit(demux) { mpc_demux_exit(demux); };
+
 	mpc_streaminfo info;
 	mpc_demux_get_info(demux, &info);
-	mpc_demux_exit(demux);
 
 	return SongTime::FromS(mpc_streaminfo_get_length(&info));
 }