Andrew Nguyen : krnl386.exe: Fix a potential leak and NULL dereference in DPMI_xrealloc.
Module: wine Branch: master Commit: be5d66f5d8df2fd90b6a0274cb12fe69a0d7385a URL: http://source.winehq.org/git/wine.git/?a=commit;h=be5d66f5d8df2fd90b6a0274cb... Author: Andrew Nguyen <anguyen(a)codeweavers.com> Date: Sun Jul 18 16:23:21 2010 -0500 krnl386.exe: Fix a potential leak and NULL dereference in DPMI_xrealloc. --- dlls/krnl386.exe16/int31.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dlls/krnl386.exe16/int31.c b/dlls/krnl386.exe16/int31.c index eb0f2c9..edcf0b3 100644 --- a/dlls/krnl386.exe16/int31.c +++ b/dlls/krnl386.exe16/int31.c @@ -263,21 +263,21 @@ static void DPMI_xfree( LPVOID ptr ) * * 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; - 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 ); return NULL; } - if (mbi.State == MEM_FREE) + if (mbi.State == MEM_FREE) { FIXME( "realloc of DPMI_xallocd region %p?\n", ptr ); return NULL; @@ -289,11 +289,17 @@ static LPVOID DPMI_xrealloc( LPVOID ptr, DWORD newsize ) if (newsize <= mbi.RegionSize) return ptr; + newptr = DPMI_xalloc( newsize ); + if (!newptr) + return NULL; + memcpy( newptr, ptr, mbi.RegionSize ); DPMI_xfree( ptr ); + + return newptr; } - return newptr; + return DPMI_xalloc( newsize ); }
participants (1)
-
Alexandre Julliard