1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

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.

Reviewed-by: softworkz . <softworkz-at-hotmail.com@ffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-15 02:15:20 +02:00
parent 50ef4b2a6b
commit f873734f84

View File

@ -144,6 +144,12 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
goto fail; 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))) { if (!(tctx->priv = av_mallocz(formatter->priv_size))) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
@ -161,15 +167,12 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
goto fail; goto fail;
} }
tctx->class = &textcontext_class;
tctx->formatter = formatter; tctx->formatter = formatter;
tctx->level = -1; tctx->level = -1;
tctx->sections = sections; tctx->sections = sections;
tctx->nb_sections = nb_sections; tctx->nb_sections = nb_sections;
tctx->writer = writer_context; tctx->writer = writer_context;
av_opt_set_defaults(tctx);
if (formatter->priv_class) { if (formatter->priv_class) {
void *priv_ctx = tctx->priv; void *priv_ctx = tctx->priv;
*(const AVClass **)priv_ctx = formatter->priv_class; *(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) if (tctx->formatter->init)
ret = tctx->formatter->init(tctx); ret = tctx->formatter->init(tctx);
if (ret < 0) if (ret < 0)