Browse code

lavfi/overlay: fix crash in case of invalid expression

Stefano Sabatini authored on 2013/04/12 06:54:24
Showing 1 changed files
... ...
@@ -170,16 +170,21 @@ static void eval_expr(AVFilterContext *ctx, enum EvalTarget eval_tgt)
170 170
 static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
171 171
 {
172 172
     int ret;
173
+    AVExpr *old = NULL;
173 174
 
174 175
     if (*pexpr)
175
-        av_expr_free(*pexpr);
176
-    *pexpr = NULL;
176
+        old = *pexpr;
177 177
     ret = av_expr_parse(pexpr, expr, var_names,
178 178
                         NULL, NULL, NULL, NULL, 0, log_ctx);
179
-    if (ret < 0)
179
+    if (ret < 0) {
180 180
         av_log(log_ctx, AV_LOG_ERROR,
181 181
                "Error when evaluating the expression '%s'\n", expr);
182
-    return ret;
182
+        *pexpr = old;
183
+        return ret;
184
+    }
185
+
186
+    av_expr_free(old);
187
+    return 0;
183 188
 }
184 189
 
185 190
 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,