Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] mfenc: Fix double frees on init errors
@ 2023-01-31 13:16 Martin Storsjö
  0 siblings, 0 replies; only message in thread
From: Martin Storsjö @ 2023-01-31 13:16 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Gyan Doshi, Cameron Gutman

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 --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;
     uninit_com_mf(f);
 }
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)
         ICodecAPI_Release(c->codec_api);
+    c->codec_api = NULL;
 
     if (c->async_events)
         IMFMediaEventGenerator_Release(c->async_events);
+    c->async_events = NULL;
 
 #if !HAVE_UWP
     if (c->library)
-- 
2.37.1 (Apple Git-137.1)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-31 13:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 13:16 [FFmpeg-devel] [PATCH] mfenc: Fix double frees on init errors Martin Storsjö

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git