From 0a182581f6f18a476be2957402c66545681afb9f Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Tue, 15 Apr 2025 01:45:54 +0200
Subject: [PATCH 08/12] fftools/textformat/avtextformat: Fix segfault upon
 allocation error

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 fftools/textformat/avtextformat.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c
index c1b5eefab4..7edf7901e4 100644
--- a/fftools/textformat/avtextformat.c
+++ b/fftools/textformat/avtextformat.c
@@ -590,10 +590,12 @@ int avtextwriter_context_close(AVTextWriterContext **pwctx)
     if (!wctx)
         return EINVAL;
 
-    if (wctx->writer->uninit)
-        wctx->writer->uninit(wctx);
-    if (wctx->writer->priv_class)
-        av_opt_free(wctx->priv);
+    if (wctx->writer) {
+        if (wctx->writer->uninit)
+            wctx->writer->uninit(wctx);
+        if (wctx->writer->priv_class)
+            av_opt_free(wctx->priv);
+    }
     av_freep(&wctx->priv);
     av_freep(pwctx);
     return ret;
-- 
2.45.2