PR #20969 opened by Jack Lau (JackLau)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20969
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20969.patch

Fix #20712

When print_sdp() fails during rtp streaming, sch_start()
returns error code without calling wirte_trailer, causing
a memory leak.

Since mux->init() (rtp_write_header) already run before
print_sdp(), so we should wirte_trailer() before exit program.

The av_write_trailer() only runs when mux->header_written is
ture so this change won't break other case.

Signed-off-by: Jack Lau <[email protected]>


>From 063e729243a76e71cb7ee9f13d1d723ea1f135cf Mon Sep 17 00:00:00 2001
From: Jack Lau <[email protected]>
Date: Wed, 19 Nov 2025 19:35:37 +0800
Subject: [PATCH] fftools/ffmpeg: fix memleak when sdp create failed

Fix #20712

When print_sdp() fails during rtp streaming, sch_start()
returns error code without calling wirte_trailer, causing
a memory leak.

Since mux->init() (rtp_write_header) already run before
print_sdp(), so we should wirte_trailer() before exit program.

The av_write_trailer() only runs when mux->header_written is
ture so this change won't break other case.

Signed-off-by: Jack Lau <[email protected]>
---
 fftools/ffmpeg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 444d027c15..12707782f6 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -891,7 +891,7 @@ static int transcode(Scheduler *sch)
 
     ret = sch_start(sch);
     if (ret < 0)
-        return ret;
+        goto end;
 
     if (stdin_interaction) {
         av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
@@ -915,7 +915,7 @@ static int transcode(Scheduler *sch)
     }
 
     ret = sch_stop(sch, &transcode_ts);
-
+end:
     /* write the trailer if needed */
     for (int i = 0; i < nb_output_files; i++) {
         int err = of_write_trailer(output_files[i]);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to