From 0b299f679851e45c684f5690c948c437ef3a8ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 7 May 2017 17:50:18 +0000 Subject: [PATCH] [NTOS]: Fix a potential memory leak. - If one of the ZwSetValueKey function fails, 'Node->ServiceName.Buffer' is leaked. - Also use 'L' prefix for wide characters. Patch by Lesan Ilie, thanks! - Use "P(C)WSTR" instead of win32 "LP(C)WSTR" string pointer types (by me). CORE-13207 #resolve svn path=/trunk/; revision=74491 --- reactos/ntoskrnl/io/pnpmgr/pnpmgr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c index 5f00b2d853f..d18b806c9ff 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c @@ -1144,6 +1144,7 @@ IopCreateDeviceNode(PDEVICE_NODE ParentNode, if (!NT_SUCCESS(Status)) { + ExFreePool(Node->ServiceName.Buffer); ExFreePoolWithTag(Node, TAG_IO_DEVNODE); return Status; } @@ -1437,7 +1438,7 @@ IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, HANDLE hParent = NULL, hKey; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; - LPCWSTR Current, Last; + PCWSTR Current, Last; USHORT Length; NTSTATUS Status; @@ -1462,7 +1463,7 @@ IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, /* Go up to the end of the string */ while (Current <= Last) { - if (Current != Last && *Current != '\\') + if (Current != Last && *Current != L'\\') { /* Not the end of the string and not a separator */ Current++; @@ -1510,7 +1511,7 @@ IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, /* Start with this new parent key */ hParent = hKey; Current++; - KeyName.Buffer = (LPWSTR)Current; + KeyName.Buffer = (PWSTR)Current; } return STATUS_UNSUCCESSFUL; @@ -4258,7 +4259,7 @@ IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, static WCHAR EnumKeyName[] = L"Enum\\"; static WCHAR DeviceParametersKeyName[] = L"Device Parameters"; ULONG KeyNameLength; - LPWSTR KeyNameBuffer; + PWSTR KeyNameBuffer; UNICODE_STRING KeyName; ULONG DriverKeyLength; OBJECT_ATTRIBUTES ObjectAttributes;