1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

audio_decoder: fix more memleaks and dangling files

This commit is contained in:
Megamouse 2024-01-09 20:45:23 +01:00
parent b67837c0ef
commit 4ad4badcfe
2 changed files with 20 additions and 10 deletions

View File

@ -278,7 +278,7 @@ public:
#endif
AVCodecContext* ctx = nullptr;
AVFormatContext* fmt = nullptr;
u8* io_buf;
u8* io_buf = nullptr;
struct AudioReader
{
@ -372,15 +372,16 @@ public:
if (ctx)
{
avcodec_close(ctx);
avformat_close_input(&fmt);
avcodec_free_context(&ctx);
}
if (io_buf)
{
av_freep(&io_buf);
}
if (fmt)
{
if (io_buf)
{
av_free(io_buf);
}
if (fmt->pb) av_free(fmt->pb);
if (fmt->pb) av_freep(&fmt->pb);
avformat_close_input(&fmt);
avformat_free_context(fmt);
}
}

View File

@ -302,13 +302,22 @@ namespace utils
if (sws)
sws_freeContext(sws);
if (audio.context)
{
avcodec_close(audio.context);
avcodec_free_context(&audio.context);
}
if (video.context)
{
avcodec_close(video.context);
avcodec_free_context(&video.context);
}
// AVCodec is managed by libavformat, no need to free it
// see: https://stackoverflow.com/a/18047320
if (format_context)
{
avformat_close_input(&format_context);
avformat_free_context(format_context);
}
//if (stream)
// av_free(stream);
if (kill_callback)
@ -626,7 +635,7 @@ namespace utils
}
// Resample frames
u8* buffer;
u8* buffer = nullptr;
const int align = 1;
const int buffer_size = av_samples_alloc(&buffer, nullptr, dst_channels, av.audio.frame->nb_samples, dst_format, align);
if (buffer_size < 0)
@ -642,7 +651,7 @@ namespace utils
media_log.error("audio_decoder: Error converting frame: %d='%s'", frame_count, av_error_to_string(frame_count));
has_error = true;
if (buffer)
av_free(buffer);
av_freep(&buffer);
return;
}
@ -660,7 +669,7 @@ namespace utils
}
if (buffer)
av_free(buffer);
av_freep(&buffer);
media_log.notice("audio_decoder: decoded frame_count=%d buffer_size=%d timestamp_us=%d", frame_count, buffer_size, av.audio.frame->best_effort_timestamp);
}