diff mbox series

[FFmpeg-devel,21/24] lavfi/vf_scale: factorize freeing the sws contexts

Message ID 20210531075515.19544-21-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/24] sws: remove unnecessary braces | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Anton Khirnov May 31, 2021, 7:55 a.m. UTC
---
 libavfilter/vf_scale.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer June 1, 2021, 12:35 p.m. UTC | #1
On Mon, May 31, 2021 at 09:55:12AM +0200, Anton Khirnov wrote:
> ---
>  libavfilter/vf_scale.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 759499395f..8516919556 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -328,16 +328,24 @@  static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
     return 0;
 }
 
+static void scaler_free(ScaleContext *s)
+{
+    sws_freeContext(s->sws);
+    sws_freeContext(s->isws[0]);
+    sws_freeContext(s->isws[1]);
+
+    s->sws     = NULL;
+    s->isws[0] = NULL;
+    s->isws[1] = NULL;
+}
+
 static av_cold void uninit(AVFilterContext *ctx)
 {
     ScaleContext *scale = ctx->priv;
     av_expr_free(scale->w_pexpr);
     av_expr_free(scale->h_pexpr);
     scale->w_pexpr = scale->h_pexpr = NULL;
-    sws_freeContext(scale->sws);
-    sws_freeContext(scale->isws[0]);
-    sws_freeContext(scale->isws[1]);
-    scale->sws = NULL;
+    scaler_free(scale);
     av_dict_free(&scale->opts);
 }
 
@@ -512,13 +520,8 @@  static int config_props(AVFilterLink *outlink)
     if (outfmt == AV_PIX_FMT_PAL8) outfmt = AV_PIX_FMT_BGR8;
     scale->output_is_pal = av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PAL;
 
-    if (scale->sws)
-        sws_freeContext(scale->sws);
-    if (scale->isws[0])
-        sws_freeContext(scale->isws[0]);
-    if (scale->isws[1])
-        sws_freeContext(scale->isws[1]);
-    scale->isws[0] = scale->isws[1] = scale->sws = NULL;
+    scaler_free(scale);
+
     if (inlink0->w == outlink->w &&
         inlink0->h == outlink->h &&
         !scale->out_color_matrix &&