obs-qsv11: Close MFX session and unload loader - #13771
Open
lazyboson wants to merge 3 commits into
Open
Conversation
Member
|
Please properly fill out the PR template. This smells AI-generated, which is not permitted per our contribution policy. |
Author
Sorry — the description was badly written and I mangled the template. Will redo the description, but there is a genuine thread and memory leak, when we use the intel gpu. I am building a screen recording application on top of libobs. The code is mine and I can walk through the session/loader teardown ordering or |
Member
|
Thanks, please update the description to properly fill out the template, and we will review. |
lazyboson
force-pushed
the
qsv-close-session
branch
from
August 11, 2026 20:44
d390105 to
a444c46
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Initialize()in the Windows backend creates anmfxLoaderand an MFX session, but never releases either. The data out-parameter was unused (UNUSED_PARAMETER(data)) and ReleaseSessionData() was an empty stub, so the loader was dropped on the floor. ClearData() also only called MFXVideoENCODE_Close(), never MFXClose(), so the session itself was leaked too.This stores the loader in the data pointer that Initialize() already receives, and closes the session and unloads the loader in ClearData(). MFXClose() is moved above the Release() block because the session's scheduler still holds the D3D11 device handle installed by MFXVideoCORE_SetHandle() — releasing the device first and closing the session afterwards [describe what you saw: hang on shutdown / access violation in libmfx / etc].
The Linux backend already tracked per-session state, so this just adds the loader to linux_data and unloads it alongside the VADisplay. Both backends also now clean up the loader on the MFXCreateSession() failure path, which previously returned early via MSDK_CHECK_RESULT and leaked.
Motivation and Context
I have been developing a cross-platform screen-recording application on top of libobs, during soak testing of application over 24 hours when i was using the intel encoding driver, memory was growing continously, i have taken dump of memory and analyzed, initially i though may be intel driver is culprit but on further analysis this dll seems have issue due to following reason -
libobscreates a fresh encoder instance every time the output is activated, so one session and one loader leak per recording. Each leaked session keeps roughly [N] threads alive and holds [N] MB.Thread count grows the same way — [N] at baseline, [N] after 8 recordings on stock, flat on the patched build.This matters most for long-running or automated setups. I hit it building a recording application on top of libobs, where OBS stays up across many start/stop cycles.
How Has This Been Tested?
I have tested this on Windows 11, with Intel Iris Xe, driver 32.0.101.7088. OBS Studio 32.2.1 portable was installed having advanced output with obs_qsv11_v2 (H.264), I have used video configuration 1280x720, 30fps and CBR 5000. I have started and stopped recording eight times, watching memory and thread count after each stop, on both the shipped obs-qsv11.dll and a build from this branch. Recordings play back fine and I saw no shutdown crashes or hangs.
I have not tested the Linux path — I don't have a VA-API machine set up. That change mirrors the existing vaTerminate/close(fd) teardown, but it would be good to have someone confirm it.
Types of changes
Checklist: