mirror of
https://github.com/reactos/reactos.git
synced 2025-04-28 01:11:35 +00:00
- 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
This commit is contained in:
parent
58f165a052
commit
2af89e434c
1 changed files with 11 additions and 7 deletions
|
@ -813,12 +813,15 @@ GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize)
|
||||||
HANDLE KeyHandle;
|
HANDLE KeyHandle;
|
||||||
PKEY_VALUE_PARTIAL_INFORMATION Kvpi;
|
PKEY_VALUE_PARTIAL_INFORMATION Kvpi;
|
||||||
DWORD KvpiSize;
|
DWORD KvpiSize;
|
||||||
|
BOOL bRetValue;
|
||||||
|
|
||||||
|
bRetValue = FALSE;
|
||||||
|
|
||||||
/* Convert the codepage number to string. */
|
/* Convert the codepage number to string. */
|
||||||
ValueName.Buffer = ValueNameBuffer;
|
ValueName.Buffer = ValueNameBuffer;
|
||||||
ValueName.MaximumLength = sizeof(ValueNameBuffer);
|
ValueName.MaximumLength = sizeof(ValueNameBuffer);
|
||||||
if (!NT_SUCCESS(RtlIntegerToUnicodeString(CodePage, 10, &ValueName)))
|
if (!NT_SUCCESS(RtlIntegerToUnicodeString(CodePage, 10, &ValueName)))
|
||||||
return FALSE;
|
return bRetValue;
|
||||||
|
|
||||||
/* Open the registry key containing file name mappings. */
|
/* Open the registry key containing file name mappings. */
|
||||||
RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System\\"
|
RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System\\"
|
||||||
|
@ -828,17 +831,17 @@ GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize)
|
||||||
Status = NtOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
|
Status = NtOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
return FALSE;
|
return bRetValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate buffer that will be used to query the value data. */
|
/* Allocate buffer that will be used to query the value data. */
|
||||||
KvpiSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
|
KvpiSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
|
||||||
(MAX_PATH * sizeof(WCHAR));
|
(MAX_PATH * sizeof(WCHAR));
|
||||||
Kvpi = HeapAlloc(GetProcessHeap(), 0, KvpiSize);
|
Kvpi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, KvpiSize);
|
||||||
if (Kvpi == NULL)
|
if (Kvpi == NULL)
|
||||||
{
|
{
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
return FALSE;
|
return bRetValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Query the file name for our code page. */
|
/* Query the file name for our code page. */
|
||||||
|
@ -856,10 +859,11 @@ GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize)
|
||||||
lstrcpynW(FileName, (WCHAR*)Kvpi->Data,
|
lstrcpynW(FileName, (WCHAR*)Kvpi->Data,
|
||||||
min(Kvpi->DataLength / sizeof(WCHAR), FileNameSize));
|
min(Kvpi->DataLength / sizeof(WCHAR), FileNameSize));
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
/* free temporary buffer */
|
||||||
|
HeapFree(GetProcessHeap(),0,Kvpi);
|
||||||
|
return bRetValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue