krnl386.exe: Fix a potential leak and NULL dereference in DPMI_xrealloc.

This commit is contained in:
Andrew Nguyen 2010-07-18 16:23:21 -05:00 committed by Alexandre Julliard
parent ea7bcc6c3f
commit be5d66f5d8
1 changed files with 13 additions and 7 deletions

View File

@ -266,11 +266,11 @@ static void DPMI_xfree( LPVOID ptr )
static LPVOID DPMI_xrealloc( LPVOID ptr, DWORD newsize ) static LPVOID DPMI_xrealloc( LPVOID ptr, DWORD newsize )
{ {
MEMORY_BASIC_INFORMATION mbi; MEMORY_BASIC_INFORMATION mbi;
LPVOID newptr;
newptr = DPMI_xalloc( newsize );
if (ptr) if (ptr)
{ {
LPVOID newptr;
if (!VirtualQuery(ptr,&mbi,sizeof(mbi))) if (!VirtualQuery(ptr,&mbi,sizeof(mbi)))
{ {
FIXME( "realloc of DPMI_xallocd region %p?\n", ptr ); FIXME( "realloc of DPMI_xallocd region %p?\n", ptr );
@ -289,11 +289,17 @@ static LPVOID DPMI_xrealloc( LPVOID ptr, DWORD newsize )
if (newsize <= mbi.RegionSize) if (newsize <= mbi.RegionSize)
return ptr; return ptr;
newptr = DPMI_xalloc( newsize );
if (!newptr)
return NULL;
memcpy( newptr, ptr, mbi.RegionSize ); memcpy( newptr, ptr, mbi.RegionSize );
DPMI_xfree( ptr ); DPMI_xfree( ptr );
return newptr;
} }
return newptr; return DPMI_xalloc( newsize );
} }