diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 87a3f04e25..f4c532e414 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -159,6 +159,8 @@ struct Atrac { p.Do(has_data_buf); if (has_data_buf) { if (p.mode == p.MODE_READ) { + if (data_buf) + delete [] data_buf; data_buf = new u8[first.filesize]; } p.DoArray(data_buf, first.filesize); @@ -600,8 +602,10 @@ u32 _AtracDecodeData(int atracID, u8* outbuf, u32 *SamplesNum, u32* finish, int av_init_packet(&packet); int got_frame, avret; while (av_read_frame(atrac->pFormatCtx, &packet) >= 0) { - if (packet.stream_index != atrac->audio_stream_index) + if (packet.stream_index != atrac->audio_stream_index) { + av_free_packet(&packet); continue; + } got_frame = 0; int bytes_in_packet = packet.size; @@ -611,6 +615,7 @@ u32 _AtracDecodeData(int atracID, u8* outbuf, u32 *SamplesNum, u32* finish, int // Let's try the next frame. } else if (avret < 0) { ERROR_LOG(ME, "avcodec_decode_audio4: Error decoding audio %d", avret); + av_free_packet(&packet); atrac->failedDecode = true; // No need to free the packet if decode_audio4 fails. // Avoid getting stuck in a loop (Virtua Tennis) @@ -1770,8 +1775,10 @@ int sceAtracLowLevelDecode(int atracID, u32 sourceAddr, u32 sourceBytesConsumedA av_init_packet(&packet); int got_frame, avret; while (av_read_frame(atrac->pFormatCtx, &packet) >= 0) { - if (packet.stream_index != atrac->audio_stream_index) + if (packet.stream_index != atrac->audio_stream_index) { + av_free_packet(&packet); continue; + } got_frame = 0; avret = avcodec_decode_audio4(atrac->pCodecCtx, atrac->pFrame, &got_frame, &packet); diff --git a/Core/HLE/sceMp3.cpp b/Core/HLE/sceMp3.cpp index 3d3468ccb9..d9b1ca726b 100644 --- a/Core/HLE/sceMp3.cpp +++ b/Core/HLE/sceMp3.cpp @@ -175,6 +175,7 @@ int sceMp3Decode(u32 mp3, u32 outPcmPtr) { memset(&frame, 0, sizeof(frame)); AVPacket packet; memset(&packet, 0, sizeof(packet)); + av_init_packet(&packet); int got_frame = 0, ret; static int audio_frame_count = 0; @@ -344,6 +345,9 @@ u32 sceMp3ReserveMp3Handle(u32 mp3Addr) { ctx->mp3Bitrate = 128; ctx->mp3SamplingRate = 44100; + if (mp3Map.find(mp3Addr) != mp3Map.end()) { + delete mp3Map[mp3Addr]; + } mp3Map[mp3Addr] = ctx; return mp3Addr; }