[FFmpeg-devel] [PATCH 1/2] lavfi/f_sendcmd: add helper to clear Command

Marvin Scholz epirat07 at gmail.com
Thu Jan 30 02:25:51 EET 2025


Makes clearing the Command more explicit and
consistent.
---
 libavfilter/f_sendcmd.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavfilter/f_sendcmd.c b/libavfilter/f_sendcmd.c
index d5d72e6410..8a0c368108 100644
--- a/libavfilter/f_sendcmd.c
+++ b/libavfilter/f_sendcmd.c
@@ -144,6 +144,18 @@ static void skip_comments(const char **buf)
 
 #define COMMAND_DELIMS " \f\t\n\r,;"
 
+/**
+ * Clears fields and frees the buffers used by @p cmd
+ */
+static void clear_command(Command *cmd)
+{
+    cmd->flags = 0;
+    cmd->index = 0;
+    av_freep(&cmd->target);
+    av_freep(&cmd->command);
+    av_freep(&cmd->arg);
+}
+
 static int parse_command(Command *cmd, int cmd_count, int interval_count,
                          const char **buf, void *log_ctx)
 {
@@ -223,9 +235,7 @@ static int parse_command(Command *cmd, int cmd_count, int interval_count,
     return 1;
 
 fail:
-    av_freep(&cmd->target);
-    av_freep(&cmd->command);
-    av_freep(&cmd->arg);
+    clear_command(cmd);
     return ret;
 }
 
@@ -477,9 +487,7 @@ static av_cold void uninit(AVFilterContext *ctx)
         Interval *interval = &s->intervals[i];
         for (j = 0; j < interval->nb_commands; j++) {
             Command *cmd = &interval->commands[j];
-            av_freep(&cmd->target);
-            av_freep(&cmd->command);
-            av_freep(&cmd->arg);
+            clear_command(cmd);
         }
         av_freep(&interval->commands);
     }
-- 
2.39.5 (Apple Git-154)



More information about the ffmpeg-devel mailing list