Author: janderwald
Date: Thu Sep 6 23:57:19 2007
New Revision: 28906
URL:
http://svn.reactos.org/svn/reactos?rev=28906&view=rev
Log:
- fix memory leak in GetCPFileNameFromRegistry
- bug report + patch by Daniel Zimmermann / netzimme(a)aol.com
See issue #2637 for more details.
Modified:
trunk/reactos/dll/win32/kernel32/misc/nls.c
Modified: trunk/reactos/dll/win32/kernel32/misc/nls.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/nl…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/nls.c (original)
+++ trunk/reactos/dll/win32/kernel32/misc/nls.c Thu Sep 6 23:57:19 2007
@@ -813,12 +813,15 @@
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 @@
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 @@
lstrcpynW(FileName, (WCHAR*)Kvpi->Data,
min(Kvpi->DataLength / sizeof(WCHAR), FileNameSize));
}
- return TRUE;
- }
-
- return FALSE;
+ }
+
+ /* free temporary buffer */
+ HeapFree(GetProcessHeap(),0,Kvpi);
+ return bRetValue;
}
/**