diff --git a/rpcs3/Emu/Cell/Modules/cellAdec.cpp b/rpcs3/Emu/Cell/Modules/cellAdec.cpp index c8b7ad2046..ce6103652e 100644 --- a/rpcs3/Emu/Cell/Modules/cellAdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAdec.cpp @@ -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); } } diff --git a/rpcs3/util/media_utils.cpp b/rpcs3/util/media_utils.cpp index fa59c2a81e..fd3da999ca 100644 --- a/rpcs3/util/media_utils.cpp +++ b/rpcs3/util/media_utils.cpp @@ -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); }