From 2af89e434c921ad223ebf3a53508061861007d19 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Thu, 6 Sep 2007 19:57:19 +0000 Subject: [PATCH] - fix memory leak in GetCPFileNameFromRegistry - bug report + patch by Daniel Zimmermann / netzimme@aol.com See issue #2637 for more details. svn path=/trunk/; revision=28906 --- reactos/dll/win32/kernel32/misc/nls.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/reactos/dll/win32/kernel32/misc/nls.c b/reactos/dll/win32/kernel32/misc/nls.c index 22c28f22a8b..cc1a20e307a 100644 --- a/reactos/dll/win32/kernel32/misc/nls.c +++ b/reactos/dll/win32/kernel32/misc/nls.c @@ -813,12 +813,15 @@ GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize) HANDLE KeyHandle; PKEY_VALUE_PARTIAL_INFORMATION Kvpi; DWORD KvpiSize; + BOOL bRetValue; + + bRetValue = FALSE; /* Convert the codepage number to string. */ ValueName.Buffer = ValueNameBuffer; ValueName.MaximumLength = sizeof(ValueNameBuffer); if (!NT_SUCCESS(RtlIntegerToUnicodeString(CodePage, 10, &ValueName))) - return FALSE; + return bRetValue; /* Open the registry key containing file name mappings. */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System\\" @@ -828,17 +831,17 @@ GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize) Status = NtOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes); if (!NT_SUCCESS(Status)) { - return FALSE; + return bRetValue; } /* Allocate buffer that will be used to query the value data. */ KvpiSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + (MAX_PATH * sizeof(WCHAR)); - Kvpi = HeapAlloc(GetProcessHeap(), 0, KvpiSize); + Kvpi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, KvpiSize); if (Kvpi == NULL) { NtClose(KeyHandle); - return FALSE; + return bRetValue; } /* Query the file name for our code page. */ @@ -856,10 +859,11 @@ GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize) lstrcpynW(FileName, (WCHAR*)Kvpi->Data, min(Kvpi->DataLength / sizeof(WCHAR), FileNameSize)); } - return TRUE; } - - return FALSE; + + /* free temporary buffer */ + HeapFree(GetProcessHeap(),0,Kvpi); + return bRetValue; } /**