diff mbox series

[FFmpeg-devel] mfenc: Fix double frees on init errors

Message ID 20230131131632.87370-1-martin@martin.st
State New
Headers show
Series [FFmpeg-devel] mfenc: Fix double frees on init errors | expand


Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Martin Storsjö Jan. 31, 2023, 1:16 p.m. UTC
Make mf_close safe to call multiple times; it currently isn't
called more than once, but for clarity, make it safe to call
more than once.

If there are failures in ff_instantiate_mf, that function
calls uninit_com_mf() on its own. Make sure that the second
call to uninit_com_mf from ff_free_mf (from mf_close) is a
no-op in that case.

Signed-off-by: Martin Storsjö <martin@martin.st>
 libavcodec/mf_utils.c | 6 ++++--
 libavcodec/mfenc.c    | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/libavcodec/mf_utils.c b/libavcodec/mf_utils.c
index 48e3a63efc..50b9fdb2c4 100644
--- a/libavcodec/mf_utils.c
+++ b/libavcodec/mf_utils.c
@@ -642,8 +642,10 @@  error_uninit_mf:
 void ff_free_mf(MFFunctions *f, IMFTransform **mft)
-    if (*mft)
-        IMFTransform_Release(*mft);
+    if (!*mft)
+        return;
+    IMFTransform_Release(*mft);
     *mft = NULL;
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index f3415df10b..e3b5fb1600 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -1184,9 +1184,11 @@  static int mf_close(AVCodecContext *avctx)
     if (c->codec_api)
+    c->codec_api = NULL;
     if (c->async_events)
+    c->async_events = NULL;
 #if !HAVE_UWP
     if (c->library)