[FFmpeg-cvslog] fftools/ffmpeg_mux: avoid leaking pkt on errors

Anton Khirnov git at videolan.org
Sat Aug 13 15:01:28 EEST 2022


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Aug  9 15:19:41 2022 +0200| [ee2092ddeceb1041d130b4680b3f58fd86a4904c] | committer: Anton Khirnov

fftools/ffmpeg_mux: avoid leaking pkt on errors

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ee2092ddeceb1041d130b4680b3f58fd86a4904c
---

 fftools/ffmpeg_mux.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 08a76f0066..b424ef0021 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -97,8 +97,10 @@ static int write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
 
     fs = filesize(s->pb);
     atomic_store(&of->mux->last_filesize, fs);
-    if (fs >= of->mux->limit_filesize)
-        return AVERROR_EOF;
+    if (fs >= of->mux->limit_filesize) {
+        ret = AVERROR_EOF;
+        goto fail;
+    }
 
     if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) ||
         (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))
@@ -138,8 +140,11 @@ static int write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
                 av_log(s, loglevel, "Non-monotonous DTS in output stream "
                        "%d:%d; previous: %"PRId64", current: %"PRId64"; ",
                        ost->file_index, ost->st->index, ms->last_mux_dts, pkt->dts);
-                if (exit_on_error)
-                    return AVERROR(EINVAL);
+                if (exit_on_error) {
+                    ret = AVERROR(EINVAL);
+                    goto fail;
+                }
+
                 av_log(s, loglevel, "changing to %"PRId64". This may result "
                        "in incorrect timestamps in the output file.\n",
                        max);
@@ -170,10 +175,13 @@ static int write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
     ret = av_interleaved_write_frame(s, pkt);
     if (ret < 0) {
         print_error("av_interleaved_write_frame()", ret);
-        return ret;
+        goto fail;
     }
 
     return 0;
+fail:
+    av_packet_unref(pkt);
+    return ret;
 }
 
 static int sync_queue_process(OutputFile *of, OutputStream *ost, AVPacket *pkt)



More information about the ffmpeg-cvslog mailing list