[FFmpeg-cvslog] lavfi/hue: simplify/fix setting logic in set_options()

Stefano Sabatini git at videolan.org
Sun Sep 23 00:52:58 CEST 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sun Sep 23 00:26:30 2012 +0200| [7fe1ecefe17b0146d49cd0003f80266a481d1faa] | committer: Stefano Sabatini

lavfi/hue: simplify/fix setting logic in set_options()

Parse expression only when a new value is explicitly specified.

In particular, avoid double free in case an old expression value is
cached, it is set in the context, it is freed as the old value, and
finally the pointer stored in the context is freed again when the filter
is released.

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

 libavfilter/vf_hue.c |   27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/libavfilter/vf_hue.c b/libavfilter/vf_hue.c
index e02a216..3048a59 100644
--- a/libavfilter/vf_hue.c
+++ b/libavfilter/vf_hue.c
@@ -107,8 +107,8 @@ static inline void compute_sin_and_cos(HueContext *hue)
     hue->hue_cos = rint(cos(hue->hue) * (1 << 16) * hue->saturation);
 }
 
-#define PARSE_EXPRESSION(attr, name)                                              \
-    do {                                                                          \
+#define SET_EXPRESSION(attr, name) do {                                           \
+    if (hue->attr##_expr) {                                                       \
         if ((ret = av_expr_parse(&hue->attr##_pexpr, hue->attr##_expr, var_names, \
                                  NULL, NULL, NULL, NULL, 0, ctx)) < 0) {          \
             av_log(ctx, AV_LOG_ERROR,                                             \
@@ -122,7 +122,10 @@ static inline void compute_sin_and_cos(HueContext *hue)
             av_expr_free(old_##attr##_pexpr);                                     \
             old_##attr##_pexpr = NULL;                                            \
         }                                                                         \
-    } while (0)
+    } else {                                                                      \
+        hue->attr##_expr = old_##attr##_expr;                                     \
+    }                                                                             \
+} while (0)
 
 static inline int set_options(AVFilterContext *ctx, const char *args)
 {
@@ -159,21 +162,9 @@ static inline int set_options(AVFilterContext *ctx, const char *args)
                 return AVERROR(EINVAL);
             }
 
-            /*
-             * if both 'H' and 'h' options have not been specified, restore the
-             * old values
-             */
-            if (!hue->hue_expr && !hue->hue_deg_expr) {
-                hue->hue_expr     = old_hue_expr;
-                hue->hue_deg_expr = old_hue_deg_expr;
-            }
-
-            if (hue->hue_deg_expr)
-                PARSE_EXPRESSION(hue_deg, h);
-            if (hue->hue_expr)
-                PARSE_EXPRESSION(hue, H);
-            if (hue->saturation_expr)
-                PARSE_EXPRESSION(saturation, s);
+            SET_EXPRESSION(hue_deg, h);
+            SET_EXPRESSION(hue, H);
+            SET_EXPRESSION(saturation, s);
 
             hue->flat_syntax = 0;
 



More information about the ffmpeg-cvslog mailing list