[FFmpeg-devel] [PATCH] libavcodec/tests/motion: Add check for avcodec_alloc_context3()

Jiasheng Jiang jiashengjiangcool at gmail.com
Sun Aug 3 23:32:23 EEST 2025


Add check for the return value of avcodec_alloc_context3() to avoid potential NULL pointer dereference.

Fixes: 5d48e4eafa ("Merge commit 'a6a750c7ef240b72ce01e9653343a0ddf247d196'")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool at gmail.com>
---
 libavcodec/tests/motion.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/tests/motion.c b/libavcodec/tests/motion.c
index c37fc551c3..719fba537d 100644
--- a/libavcodec/tests/motion.c
+++ b/libavcodec/tests/motion.c
@@ -129,6 +129,10 @@ int main(int argc, char **argv)
     printf("ffmpeg motion test\n");
 
     ctx = avcodec_alloc_context3(NULL);
+    if (!ctx) {
+        return 1;
+    }
+
     ctx->flags |= AV_CODEC_FLAG_BITEXACT;
     av_force_cpu_flags(0);
     ff_me_cmp_init(&cctx, ctx);
-- 
2.25.1



More information about the ffmpeg-devel mailing list