fixed returned status code in RtlAnsiStringToUnicodeString and properly free allocated memory in case converting the string failed

svn path=/trunk/; revision=20449
This commit is contained in:
Thomas Bluemel 2005-12-30 00:18:48 +00:00
parent 7d203ec76d
commit 484ec5bcf7

View file

@ -75,15 +75,15 @@ RtlAnsiStringToUnicodeString(
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2; if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
UniDest->Length = (USHORT)Length - sizeof(WCHAR); UniDest->Length = (USHORT)Length - sizeof(WCHAR);
if (AllocateDestinationString == TRUE) if (AllocateDestinationString)
{ {
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR); UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
UniDest->MaximumLength = Length; UniDest->MaximumLength = Length;
if (!UniDest->Buffer) return STATUS_NO_MEMORY; if (!UniDest->Buffer) return STATUS_NO_MEMORY;
} }
else if (Length >= UniDest->MaximumLength) else if (UniDest->Length >= UniDest->MaximumLength)
{ {
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_OVERFLOW;
} }
Status = RtlMultiByteToUnicodeN(UniDest->Buffer, Status = RtlMultiByteToUnicodeN(UniDest->Buffer,
@ -92,9 +92,13 @@ RtlAnsiStringToUnicodeString(
AnsiSource->Buffer, AnsiSource->Buffer,
AnsiSource->Length); AnsiSource->Length);
if (!NT_SUCCESS(Status) && AllocateDestinationString) if (!NT_SUCCESS(Status))
{ {
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR); if (AllocateDestinationString)
{
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
UniDest->Buffer = NULL;
}
return Status; return Status;
} }