From c08d300481b8ebb846cd43a473988fdbc6793d1b Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Fri, 17 Jan 2025 00:05:31 -0300
Subject: [PATCH] avformat/avformat: also clear FFFormatContext packet queue
 when closing a muxer

packet_buffer is used in mux.c, and if a muxing process fails at a point where
packets remained in said queue, they will leak.

Fixes ticket #11419

Signed-off-by: James Almer <jamrial@gmail.com>

CVE: CVE-2025-25473

Upstream-Status: Backport [https://git.ffmpeg.org/gitweb/ffmpeg.git/commitdiff/c08d300481b8ebb846cd43a473988fdbc6793d1b]

Signed-off-by: Archana Polampalli <archana.polampalli@windriver.com>
---
 libavformat/avformat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 5b8bb78..73f31cd 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -138,6 +138,7 @@ void avformat_free_context(AVFormatContext *s)
     av_dict_free(&si->id3v2_meta);
     av_packet_free(&si->pkt);
     av_packet_free(&si->parse_pkt);
+    avpriv_packet_list_free(&si->packet_buffer);
     av_freep(&s->streams);
     ff_flush_packet_queue(s);
     av_freep(&s->url);
--
2.40.0
