* [FFmpeg-devel] [PATCH 1/2] lavfi/f_sendcmd: add helper to clear Command
@ 2025-01-30 0:25 Marvin Scholz
2025-01-30 0:25 ` [FFmpeg-devel] [PATCH 2/2] lavfi/f_sendcmd: clear Command on alloc failure Marvin Scholz
0 siblings, 1 reply; 2+ messages in thread
From: Marvin Scholz @ 2025-01-30 0:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marvin Scholz
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)
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] lavfi/f_sendcmd: clear Command on alloc failure
2025-01-30 0:25 [FFmpeg-devel] [PATCH 1/2] lavfi/f_sendcmd: add helper to clear Command Marvin Scholz
@ 2025-01-30 0:25 ` Marvin Scholz
0 siblings, 0 replies; 2+ messages in thread
From: Marvin Scholz @ 2025-01-30 0:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marvin Scholz
If the command array failed to allocate, the current parsed
Command has to be cleared, else memory allocated for it
would be leaked.
Fix CID 1638635
---
libavfilter/f_sendcmd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libavfilter/f_sendcmd.c b/libavfilter/f_sendcmd.c
index 8a0c368108..64f284f4f1 100644
--- a/libavfilter/f_sendcmd.c
+++ b/libavfilter/f_sendcmd.c
@@ -263,6 +263,7 @@ static int parse_commands(Command **cmds, int *nb_cmds, int interval_count,
if (!*cmds) {
av_log(log_ctx, AV_LOG_ERROR,
"Could not (re)allocate command array\n");
+ clear_command(&cmd);
return AVERROR(ENOMEM);
}
}
--
2.39.5 (Apple Git-154)
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-30 0:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-30 0:25 [FFmpeg-devel] [PATCH 1/2] lavfi/f_sendcmd: add helper to clear Command Marvin Scholz
2025-01-30 0:25 ` [FFmpeg-devel] [PATCH 2/2] lavfi/f_sendcmd: clear Command on alloc failure Marvin Scholz
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git