diff mbox series

[FFmpeg-devel,8/9] fftools/ffmpeg_mux: deduplicate uniniting EncStats

Message ID 20231214193138.2503-8-anton@khirnov.net
State Accepted
Commit 244d2fcc49452f3c5aa0f4899c7c0c03ccc6a69e
Headers show
Series [FFmpeg-devel,1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Dec. 14, 2023, 7:31 p.m. UTC
---
 fftools/ffmpeg_mux.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 88ce3cd60c..357f34172f 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -773,6 +773,13 @@  int of_write_trailer(OutputFile *of)
     return mux_result;
 }
 
+static void enc_stats_uninit(EncStats *es)
+{
+    for (int i = 0; i < es->nb_components; i++)
+        av_freep(&es->components[i].str);
+    av_freep(&es->components);
+}
+
 static void ost_free(OutputStream **post)
 {
     OutputStream *ost = *post;
@@ -818,17 +825,9 @@  static void ost_free(OutputStream **post)
         av_freep(&ost->enc_ctx->stats_in);
     avcodec_free_context(&ost->enc_ctx);
 
-    for (int i = 0; i < ost->enc_stats_pre.nb_components; i++)
-        av_freep(&ost->enc_stats_pre.components[i].str);
-    av_freep(&ost->enc_stats_pre.components);
-
-    for (int i = 0; i < ost->enc_stats_post.nb_components; i++)
-        av_freep(&ost->enc_stats_post.components[i].str);
-    av_freep(&ost->enc_stats_post.components);
-
-    for (int i = 0; i < ms->stats.nb_components; i++)
-        av_freep(&ms->stats.components[i].str);
-    av_freep(&ms->stats.components);
+    enc_stats_uninit(&ost->enc_stats_pre);
+    enc_stats_uninit(&ost->enc_stats_post);
+    enc_stats_uninit(&ms->stats);
 
     av_freep(post);
 }