Fix possible memory leak in ProbeAndCaptureUnicodeString

Patch from Thomas Weidenmueller

svn path=/trunk/; revision=22078
This commit is contained in:
Ged Murphy
2006-05-27 15:06:51 +00:00
parent dcc771fae1
commit ae25dcdf0f
+12 -2
View File
@@ -31,7 +31,7 @@ VOID NTAPI W32kRaiseStatus(NTSTATUS Status);
#define ProbeForWriteBoolean(Ptr) ProbeForWriteGenericType(Ptr, BOOLEAN)
#define ProbeForWriteUchar(Ptr) ProbeForWriteGenericType(Ptr, UCHAR)
#define ProbeForWriteChar(Ptr) ProbeForWriteGenericType(Ptr, Char)
#define ProbeForWriteChar(Ptr) ProbeForWriteGenericType(Ptr, CHAR)
#define ProbeForWriteUshort(Ptr) ProbeForWriteGenericType(Ptr, USHORT)
#define ProbeForWriteShort(Ptr) ProbeForWriteGenericType(Ptr, SHORT)
#define ProbeForWriteUlong(Ptr) ProbeForWriteGenericType(Ptr, ULONG)
@@ -85,7 +85,7 @@ ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest,
IN PUNICODE_STRING UnsafeSrc)
{
NTSTATUS Status = STATUS_SUCCESS;
WCHAR *Buffer;
WCHAR *Buffer = NULL;
ASSERT(Dest != NULL);
/* Probe the structure and buffer*/
@@ -136,6 +136,16 @@ ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest,
}
_SEH_HANDLE
{
/* Free allocated resources and zero the destination string */
if (Buffer != NULL)
{
ExFreePool(Buffer);
}
Dest->Length = 0;
Dest->MaximumLength = 0;
Dest->Buffer = NULL;
/* Return the error code */
Status = _SEH_GetExceptionCode();
}
_SEH_END;