diff --git a/Source/Core/VideoCommon/FrameDump.cpp b/Source/Core/VideoCommon/FrameDump.cpp index ceba863b89..2773c0e0fe 100644 --- a/Source/Core/VideoCommon/FrameDump.cpp +++ b/Source/Core/VideoCommon/FrameDump.cpp @@ -333,12 +333,18 @@ void FrameDump::AddFrame(const FrameData& frame) void FrameDump::ProcessPackets() { + auto pkt = std::unique_ptr>( + av_packet_alloc(), [](AVPacket* packet) { av_packet_free(&packet); }); + + if (!pkt) + { + ERROR_LOG_FMT(FRAMEDUMP, "Could not allocate packet"); + return; + } + while (true) { - AVPacket pkt; - av_init_packet(&pkt); - - const int receive_error = avcodec_receive_packet(m_context->codec, &pkt); + const int receive_error = avcodec_receive_packet(m_context->codec, pkt.get()); if (receive_error == AVERROR(EAGAIN) || receive_error == AVERROR_EOF) { @@ -352,10 +358,10 @@ void FrameDump::ProcessPackets() break; } - av_packet_rescale_ts(&pkt, m_context->codec->time_base, m_context->stream->time_base); - pkt.stream_index = m_context->stream->index; + av_packet_rescale_ts(pkt.get(), m_context->codec->time_base, m_context->stream->time_base); + pkt->stream_index = m_context->stream->index; - if (const int write_error = av_interleaved_write_frame(m_context->format, &pkt)) + if (const int write_error = av_interleaved_write_frame(m_context->format, pkt.get())) { ERROR_LOG_FMT(FRAMEDUMP, "Error writing packet: {}", write_error); break;