From 453628946f921d0997a34b0dd750006fe3c6c1e2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 24 Oct 2013 19:12:44 -0700 Subject: [PATCH] Free mp3 contexts more carefully. --- Core/HLE/sceMp3.cpp | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Core/HLE/sceMp3.cpp b/Core/HLE/sceMp3.cpp index 22463ca6bb..412c38d659 100644 --- a/Core/HLE/sceMp3.cpp +++ b/Core/HLE/sceMp3.cpp @@ -41,10 +41,33 @@ extern "C" { static const int MP3_BITRATES[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}; struct Mp3Context { + Mp3Context() + : +#ifdef USE_FFMPEG + avformat_context(NULL), avio_context(NULL), resampler_context(NULL), +#endif + mediaengine(NULL) { + } + + ~Mp3Context() { +#ifdef USE_FFMPEG + if (avio_context != NULL) { + av_free(avio_context->buffer); + av_free(avio_context); + } + if (avformat_context != NULL) { + avformat_free_context(avformat_context); + } + if (resampler_context != NULL) { + swr_free(&resampler_context); + } +#endif + } + void DoState(PointerWrap &p) { - auto s = p.Section("Mp3Context", 1, 2); - if (!s) - return; + auto s = p.Section("Mp3Context", 1, 2); + if (!s) + return; p.Do(mp3StreamStart); p.Do(mp3StreamEnd); @@ -294,11 +317,6 @@ u32 sceMp3ReserveMp3Handle(u32 mp3Addr) { ctx->mp3Bitrate = 128; ctx->mp3SamplingRate = 44100; -#ifdef USE_FFMPEG - ctx->avformat_context = NULL; - ctx->avio_context = NULL; -#endif - mp3Map[mp3Addr] = ctx; return mp3Addr; } @@ -543,10 +561,6 @@ int sceMp3ReleaseMp3Handle(u32 mp3) { return -1; } -#ifdef USE_FFMPEG - av_free(ctx->avio_context->buffer); - av_free(ctx->avio_context); -#endif mp3Map.erase(mp3Map.find(mp3)); delete ctx;