Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Martin Storsjö" <martin@martin.st>
To: ffmpeg-devel@ffmpeg.org
Cc: Gyan Doshi <ffmpeg@gyani.pro>, Cameron Gutman <aicommander@gmail.com>
Subject: [FFmpeg-devel] [PATCH] mfenc: Fix double frees on init errors
Date: Tue, 31 Jan 2023 15:16:32 +0200
Message-ID: <20230131131632.87370-1-martin@martin.st> (raw)

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".

                 reply	other threads:[~2023-01-31 13:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230131131632.87370-1-martin@martin.st \
    --to=martin@martin.st \
    --cc=aicommander@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=ffmpeg@gyani.pro \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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