From 11cb1279b5f754901bd91e2f576f7b50129c528c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Tue, 15 Apr 2025 02:15:20 +0200 Subject: [PATCH 10/12] fftools/textformat/avtextformat: Initialize stuff earlier avtext_context_close() calls av_opt_free() on an AVTextFormatContext as well as av_bprint_finalize() on the containing section_pbuf AvBPrints, yet it can happen that the AVBPrints have not been initialized (only zeroed) and that av_opt_set_defaults() has not been called. This works, but it is not really documented to do so. So ensure that the options and the AVBPrints have been initialized when avtext_context_close() is called. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/textformat/avtextformat.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c index 5e225825ba..4a90d8664f 100644 --- a/fftools/textformat/avtextformat.c +++ b/fftools/textformat/avtextformat.c @@ -144,6 +144,12 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form goto fail; } + for (int i = 0; i < SECTION_MAX_NB_LEVELS; i++) + av_bprint_init(&tctx->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED); + + tctx->class = &textcontext_class; + av_opt_set_defaults(tctx); + if (!(tctx->priv = av_mallocz(formatter->priv_size))) { ret = AVERROR(ENOMEM); goto fail; @@ -161,15 +167,12 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form goto fail; } - tctx->class = &textcontext_class; tctx->formatter = formatter; tctx->level = -1; tctx->sections = sections; tctx->nb_sections = nb_sections; tctx->writer = writer_context; - av_opt_set_defaults(tctx); - if (formatter->priv_class) { void *priv_ctx = tctx->priv; *(const AVClass **)priv_ctx = formatter->priv_class; @@ -232,9 +235,6 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form } } - for (i = 0; i < SECTION_MAX_NB_LEVELS; i++) - av_bprint_init(&tctx->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED); - if (tctx->formatter->init) ret = tctx->formatter->init(tctx); if (ret < 0) -- 2.45.2