Commit be5d66f5 authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

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

parent ea7bcc6c
...@@ -263,21 +263,21 @@ static void DPMI_xfree( LPVOID ptr ) ...@@ -263,21 +263,21 @@ static void DPMI_xfree( LPVOID ptr )
* *
* FIXME: perhaps we could grow this mapped area... * FIXME: perhaps we could grow this mapped area...
*/ */
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)
{ {
if (!VirtualQuery(ptr,&mbi,sizeof(mbi))) LPVOID newptr;
if (!VirtualQuery(ptr,&mbi,sizeof(mbi)))
{ {
FIXME( "realloc of DPMI_xallocd region %p?\n", ptr ); FIXME( "realloc of DPMI_xallocd region %p?\n", ptr );
return NULL; return NULL;
} }
if (mbi.State == MEM_FREE) if (mbi.State == MEM_FREE)
{ {
FIXME( "realloc of DPMI_xallocd region %p?\n", ptr ); FIXME( "realloc of DPMI_xallocd region %p?\n", ptr );
return NULL; return NULL;
...@@ -289,11 +289,17 @@ static LPVOID DPMI_xrealloc( LPVOID ptr, DWORD newsize ) ...@@ -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 );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment