[WIN32K:NTUSER] Only call IntFreeSecurityBuffer() when needed, don't free NULL buffers.

Addendum to 878c2f44.
This commit is contained in:
Hermès Bélusca-Maïto 2022-05-06 20:34:52 +02:00
parent 3900cf88b3
commit d21895e6ef
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -563,7 +563,7 @@ IntResolveDesktop(
LUID ProcessLuid; LUID ProcessLuid;
USHORT StrSize; USHORT StrSize;
SIZE_T MemSize; SIZE_T MemSize;
PSECURITY_DESCRIPTOR ServiceSD = NULL; PSECURITY_DESCRIPTOR ServiceSD;
POBJECT_ATTRIBUTES ObjectAttributes = NULL; POBJECT_ATTRIBUTES ObjectAttributes = NULL;
PUNICODE_STRING ObjectName; PUNICODE_STRING ObjectName;
UNICODE_STRING WinStaName, DesktopName; UNICODE_STRING WinStaName, DesktopName;
@ -1022,16 +1022,15 @@ IntResolveDesktop(
ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR)); ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
/* /*
* Set up a security descriptor for the service. * Set up a security descriptor for the new service's window station.
* A service is generally based upon a desktop * A service has an associated window station and desktop. The newly
* and a window station. The newly created window * created window station and desktop will get this security descriptor
* station and desktop will get this security descriptor
* if such objects weren't created before. * if such objects weren't created before.
*/ */
Status = IntCreateServiceSecurity(&ServiceSD); Status = IntCreateServiceSecurity(&ServiceSD);
if (!NT_SUCCESS(Status)) 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; goto Quit;
} }
@ -1051,6 +1050,9 @@ IntResolveDesktop(
KernelMode, KernelMode,
MAXIMUM_ALLOWED, MAXIMUM_ALLOWED,
0, 0, 0, 0, 0); 0, 0, 0, 0, 0);
IntFreeSecurityBuffer(ServiceSD);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ASSERT(hWinSta == NULL); ASSERT(hWinSta == NULL);
@ -1200,8 +1202,6 @@ Quit:
{ {
*phWinSta = hWinSta; *phWinSta = hWinSta;
*phDesktop = hDesktop; *phDesktop = hDesktop;
IntFreeSecurityBuffer(ServiceSD);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
else else
@ -1218,9 +1218,6 @@ Quit:
if (hWinSta) if (hWinSta)
ObCloseHandle(hWinSta, UserMode); ObCloseHandle(hWinSta, UserMode);
if (ServiceSD)
IntFreeSecurityBuffer(ServiceSD);
SetLastNtError(Status); SetLastNtError(Status);
return Status; return Status;
} }