d3d12screencapturesrc: Fix desktop handle leak

Calling CloseDesktop() on a handle that is currently in use will fail.
Close the handle after current desktop handle change

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9136>
This commit is contained in:
Seungha Yang 2025-05-30 00:07:25 +09:00 committed by GStreamer Marge Bot
parent e2f54cc405
commit d5dfa3ef5e

View File

@ -429,13 +429,13 @@ public:
}
}
HDESK hdesk = OpenInputDesktop (0, FALSE, GENERIC_ALL);
auto prev_hdesk = GetThreadDesktop (GetCurrentThreadId ());
auto hdesk = OpenInputDesktop (0, FALSE, GENERIC_ALL);
if (hdesk) {
if (!SetThreadDesktop (hdesk)) {
GST_WARNING ("SetThreadDesktop() failed, error %lu", GetLastError());
}
CloseDesktop (hdesk);
} else {
GST_WARNING ("OpenInputDesktop() failed, error %lu", GetLastError());
}
@ -469,6 +469,12 @@ public:
if (FAILED (hr))
hr = output1->DuplicateOutput(device, &dupl_);
if (prev_hdesk)
SetThreadDesktop (prev_hdesk);
if (hdesk)
CloseDesktop (hdesk);
if (FAILED (hr)) {
if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
GST_ERROR ("Hit the max allowed number of Desktop Duplication session");