From: Patrick Hibbs Subject: [PATCH v2 4/6] wtsapi32: Allow deregistering windows in WTSUnRegisterSessionNotificationEx(). Message-Id: <20190714002104.22262-5-hibbsncc1701@gmail.com> Date: Sat, 13 Jul 2019 20:21:02 -0400 In-Reply-To: <20190714002104.22262-1-hibbsncc1701@gmail.com> References: <20190714002104.22262-1-hibbsncc1701@gmail.com> From: Patrick Hibbs Ensure the heap doesn't run out of space, and return the proper status codes. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47433 Signed-off-by: Patrick Hibbs --- v2: Fix status code based on tests, make mismatched message a trace. --- dlls/wtsapi32/wtsapi32.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/dlls/wtsapi32/wtsapi32.c b/dlls/wtsapi32/wtsapi32.c index dccd5ec1a1..8bc7348fca 100644 --- a/dlls/wtsapi32/wtsapi32.c +++ b/dlls/wtsapi32/wtsapi32.c @@ -451,12 +451,35 @@ BOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd) } /************************************************************ - * WTSUnRegisterSessionNotification (WTSAPI32.@) + * WTSUnRegisterSessionNotificationEx (WTSAPI32.@) */ BOOL WINAPI WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd) { - FIXME("Stub %p %p\n", hServer, hWnd); - return FALSE; + BOOL found = FALSE; + WTSAPI32InternalRegMNGTStr *mgntStr, *cursor2; + FIXME("Simi-Stub %p %p\n", hServer, hWnd); + + /* Only deregister a window if it was registered previously. + */ + LIST_FOR_EACH_ENTRY_SAFE(mgntStr, cursor2, &RegisteredWindowsToNotifiy, + WTSAPI32InternalRegMNGTStr, entry) + { + if ((mgntStr != NULL) && (mgntStr->hServer == hServer) && (mgntStr->hWnd == hWnd)) + { + found = TRUE; + list_remove(&mgntStr->entry); + HeapFree(GetProcessHeap(), 0, mgntStr); + } + } + + /* Log mismatched UnRegister calls. + */ + if (!found) + { + TRACE("Mismatched WTSUnRegisterSessionNotification\n"); + } + + return TRUE; } -- 2.22.0