From 4423c27e1df1e0a92beb9d0c0f8b472dcf94cabb Mon Sep 17 00:00:00 2001 From: Sverre Skodje Date: Fri, 3 Feb 2023 02:18:09 +0100 Subject: [PATCH] Fixed a memory leak in video encoder, due to improper shutdown of IMFSinkWriter. --- ScreenRecorderLibNative/OutputManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ScreenRecorderLibNative/OutputManager.cpp b/ScreenRecorderLibNative/OutputManager.cpp index 18a2f6b..5eeae70 100644 --- a/ScreenRecorderLibNative/OutputManager.cpp +++ b/ScreenRecorderLibNative/OutputManager.cpp @@ -146,7 +146,11 @@ HRESULT OutputManager::FinalizeRecording() //Dispose of MPEG4MediaSink IMFMediaSink *pSink; if (SUCCEEDED(m_SinkWriter->GetServiceForStream(MF_SINK_WRITER_MEDIASINK, GUID_NULL, IID_PPV_ARGS(&pSink)))) { + //Release the sink writer before calling Shutdown on the media sink. + //https://learn.microsoft.com/en-us/windows/win32/api/mfreadwrite/nf-mfreadwrite-mfcreatesinkwriterfrommediasink + m_SinkWriter.Release(); finalizeResult = pSink->Shutdown(); + SafeRelease(&pSink); if (FAILED(finalizeResult)) { LOG_ERROR("Failed to shut down IMFMediaSink"); }