From 5382cc11a38d7dead059df3de367c0dcf59df1fa Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Thu, 9 Jul 2015 12:38:04 +0200 Subject: [PATCH] MidiSource: Close source SDL_RWops before throwing error --- src/midisource.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/midisource.cpp b/src/midisource.cpp index fdca2e482..9cd3a4477 100644 --- a/src/midisource.cpp +++ b/src/midisource.cpp @@ -626,9 +626,20 @@ struct MidiSource : ALDataSource, MidiReadHandler std::vector data(dataLen); if (SDL_RWread(&ops, &data[0], 1, dataLen) < dataLen) + { + SDL_RWclose(&ops); throw Exception(Exception::MKXPError, "Reading midi data failed"); + } - readMidi(this, data); + try + { + readMidi(this, data); + } + catch (const Exception &) + { + SDL_RWclose(&ops); + throw; + } synth = shState->midiState().allocateSynth();