From 8d80b13cbe063d950c15de5c4bbfd29ca4045141 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Mon, 9 Mar 2026 08:41:56 +0800 Subject: [PATCH] doc/examples/remux: fix NULL pointer dereference in cleanup The cleanup path uses `ofmt->flags` to check AVFMT_NOFILE, but `ofmt` is only assigned after avformat_alloc_output_context2 succeeds. If a failure occurs between output context allocation and the `ofmt` assignment (e.g. stream_mapping allocation fails), ofmt_ctx is non-NULL while ofmt is still NULL, causing a crash. Use ofmt_ctx->oformat->flags instead, which is always valid when ofmt_ctx is non-NULL. Signed-off-by: Jun Zhao --- doc/examples/remux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/examples/remux.c b/doc/examples/remux.c index 1f002987c5..1a88f7efe6 100644 --- a/doc/examples/remux.c +++ b/doc/examples/remux.c @@ -184,7 +184,7 @@ end: avformat_close_input(&ifmt_ctx); /* close output */ - if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE)) + if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) avio_closep(&ofmt_ctx->pb); avformat_free_context(ofmt_ctx);