Clean up some atrac/mp3 potential leaks.

This commit is contained in:
Unknown W. Brackets committed 2014-03-30 15:08:38 -07:00
1 parent 0ba0dba63d
commit aea26f666c
2 files changed
+13 -2

No files matched your search

+9 -2
View File
@@ -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);
+4
View File
@@ -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;
}