From d21895e6ef982c2927857cb18d6fb30370b5db04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 6 May 2022 20:34:52 +0200 Subject: [PATCH] [WIN32K:NTUSER] Only call IntFreeSecurityBuffer() when needed, don't free NULL buffers. Addendum to 878c2f44. --- win32ss/user/ntuser/desktop.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/win32ss/user/ntuser/desktop.c b/win32ss/user/ntuser/desktop.c index fcb3a8aa009..2344fea0c01 100644 --- a/win32ss/user/ntuser/desktop.c +++ b/win32ss/user/ntuser/desktop.c @@ -563,7 +563,7 @@ IntResolveDesktop( LUID ProcessLuid; USHORT StrSize; SIZE_T MemSize; - PSECURITY_DESCRIPTOR ServiceSD = NULL; + PSECURITY_DESCRIPTOR ServiceSD; POBJECT_ATTRIBUTES ObjectAttributes = NULL; PUNICODE_STRING ObjectName; UNICODE_STRING WinStaName, DesktopName; @@ -1022,16 +1022,15 @@ IntResolveDesktop( ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR)); /* - * Set up a security descriptor for the service. - * A service is generally based upon a desktop - * and a window station. The newly created window - * station and desktop will get this security descriptor + * Set up a security descriptor for the new service's window station. + * A service has an associated window station and desktop. The newly + * created window station and desktop will get this security descriptor * if such objects weren't created before. */ Status = IntCreateServiceSecurity(&ServiceSD); if (!NT_SUCCESS(Status)) { - ERR("Failed to create a security descriptor for default window station, Status 0x%08lx\n", Status); + ERR("Failed to create a security descriptor for service window station, Status 0x%08lx\n", Status); goto Quit; } @@ -1051,6 +1050,9 @@ IntResolveDesktop( KernelMode, MAXIMUM_ALLOWED, 0, 0, 0, 0, 0); + + IntFreeSecurityBuffer(ServiceSD); + if (!NT_SUCCESS(Status)) { ASSERT(hWinSta == NULL); @@ -1200,8 +1202,6 @@ Quit: { *phWinSta = hWinSta; *phDesktop = hDesktop; - - IntFreeSecurityBuffer(ServiceSD); return STATUS_SUCCESS; } else @@ -1218,9 +1218,6 @@ Quit: if (hWinSta) ObCloseHandle(hWinSta, UserMode); - if (ServiceSD) - IntFreeSecurityBuffer(ServiceSD); - SetLastNtError(Status); return Status; }