From 25a6663243101c348117fd54613261e4914bebb0 Mon Sep 17 00:00:00 2001 From: Peter Berg Larsen Date: Mon, 14 Mar 2005 17:13:44 +0000 Subject: [PATCH] Assorted memleak fixes. Found on Michael Stefaniuc smatch list. --- dlls/user/lstr.c | 4 ++-- dlls/user/message.c | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dlls/user/lstr.c b/dlls/user/lstr.c index a25c600ed8d..bcdb3fc966a 100644 --- a/dlls/user/lstr.c +++ b/dlls/user/lstr.c @@ -625,11 +625,11 @@ DWORD WINAPI FormatMessage16( from = HeapAlloc( GetProcessHeap(), 0, strlen(source)+1 ); strcpy( from, source ); } - if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { + else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { from = HeapAlloc( GetProcessHeap(),0,200 ); sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId); } - if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { + else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { INT16 bufsize; HINSTANCE16 hinst16 = ((HINSTANCE16)lpSource & 0xffff); diff --git a/dlls/user/message.c b/dlls/user/message.c index e6bac74a50f..c802ef12495 100644 --- a/dlls/user/message.c +++ b/dlls/user/message.c @@ -1435,13 +1435,18 @@ static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM TRACE( "recv ddepack %u %x\n", size, uiHi ); if (size) { - hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ); - if (hMem && (ptr = GlobalLock( hMem ))) + if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) + return FALSE; + if ((ptr = GlobalLock( hMem ))) { memcpy( ptr, *buffer, size ); GlobalUnlock( hMem ); } - else return FALSE; + else + { + GlobalFree( hMem ); + return FALSE; + } } uiLo = (UINT)hMem; @@ -1451,8 +1456,8 @@ static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM if (size) { if (!buffer || !*buffer) return FALSE; - hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ); - if (hMem && (ptr = GlobalLock( hMem ))) + if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE; + if ((ptr = GlobalLock( hMem ))) { memcpy( ptr, *buffer, size ); GlobalUnlock( hMem ); @@ -1462,7 +1467,12 @@ static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM GlobalFree( hMem ); return FALSE; } - } + } + else + { + GlobalFree( hMem ); + return FALSE; + } } else return FALSE; *lparam = (LPARAM)hMem; break;