From 4293b614c4b4785e37c33859ab2d1a7557a2531c Mon Sep 17 00:00:00 2001 From: Peter Berg Larsen Date: Mon, 14 Mar 2005 10:03:39 +0000 Subject: [PATCH] Assorted memleak fixes. Found on Michael Stefaniuc smatch list. --- dlls/x11drv/clipboard.c | 19 ++++++++++++++----- dlls/x11drv/xrender.c | 21 +++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/dlls/x11drv/clipboard.c b/dlls/x11drv/clipboard.c index ae76f3e3640..8e42bc9372a 100644 --- a/dlls/x11drv/clipboard.c +++ b/dlls/x11drv/clipboard.c @@ -1262,13 +1262,17 @@ HANDLE X11DRV_CLIPBOARD_ImportClipboardData(LPBYTE lpdata, UINT cBytes) { /* Turn on the DDESHARE flag to enable shared 32 bit memory */ hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes); + if (hClipData == 0) return NULL; + if ((lpClipData = GlobalLock(hClipData))) { memcpy(lpClipData, lpdata, cBytes); GlobalUnlock(hClipData); } - else + else { + GlobalFree(hClipData); hClipData = 0; + } } return hClipData; @@ -1296,6 +1300,7 @@ HANDLE X11DRV_CLIPBOARD_ExportClipboardData(Window requestor, Atom aTarget, cBytes = GlobalSize(lpData->hData32); hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes); + if (hClipData == 0) return NULL; if ((lpClipData = GlobalLock(hClipData))) { @@ -1306,6 +1311,9 @@ HANDLE X11DRV_CLIPBOARD_ExportClipboardData(Window requestor, Atom aTarget, GlobalUnlock(lpData->hData32); GlobalUnlock(hClipData); + } else { + GlobalFree(hClipData); + hClipData = 0; } } @@ -1324,7 +1332,7 @@ HANDLE X11DRV_CLIPBOARD_ExportXAString(LPWINE_CLIPDATA lpData, LPDWORD lpBytes) UINT i, j; UINT size; LPWSTR uni_text; - LPSTR text, lpstr; + LPSTR text, lpstr = NULL; *lpBytes = 0; /* Assume return has zero bytes */ @@ -1333,14 +1341,14 @@ HANDLE X11DRV_CLIPBOARD_ExportXAString(LPWINE_CLIPDATA lpData, LPDWORD lpBytes) size = WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, NULL, 0, NULL, NULL); text = HeapAlloc(GetProcessHeap(), 0, size); - if (!text) - return None; + if (!text) goto done; WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, text, size, NULL, NULL); /* remove carriage returns */ lpstr = (char*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size-- ); - if(lpstr == NULL) return None; + if(lpstr == NULL) goto done; + for(i = 0,j = 0; i < size && text[i]; i++ ) { if( text[i] == '\r' && @@ -1351,6 +1359,7 @@ HANDLE X11DRV_CLIPBOARD_ExportXAString(LPWINE_CLIPDATA lpData, LPDWORD lpBytes) *lpBytes = j; /* Number of bytes in string */ +done: HeapFree(GetProcessHeap(), 0, text); GlobalUnlock(lpData->hData32); diff --git a/dlls/x11drv/xrender.c b/dlls/x11drv/xrender.c index d27751d28e6..01f67b9e513 100644 --- a/dlls/x11drv/xrender.c +++ b/dlls/x11drv/xrender.c @@ -1065,13 +1065,13 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag if(flags & (ETO_CLIPPED | ETO_OPAQUE)) { if(!lprect) { - if(flags & ETO_CLIPPED) return FALSE; - GetTextExtentPointI(hdc, glyphs, count, &sz); - done_extents = TRUE; - rc.left = x; - rc.top = y; - rc.right = x + sz.cx; - rc.bottom = y + sz.cy; + if(flags & ETO_CLIPPED) goto done; + GetTextExtentPointI(hdc, glyphs, count, &sz); + done_extents = TRUE; + rc.left = x; + rc.top = y; + rc.right = x + sz.cx; + rc.bottom = y + sz.cy; } else { rc = *lprect; } @@ -1115,7 +1115,7 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag if(count == 0) { retv = TRUE; - goto done; + goto done_unlock; } pt.x = x; @@ -1539,7 +1539,7 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag strikeoutWidth = underlineWidth; } else { otm = HeapAlloc(GetProcessHeap(), 0, nMetricsSize); - if (!otm) goto done; + if (!otm) goto done_unlock; GetOutlineTextMetricsW(hdc, nMetricsSize, otm); underlinePos = otm->otmsUnderscorePosition; @@ -1592,8 +1592,9 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag retv = TRUE; -done: +done_unlock: X11DRV_UnlockDIBSection( physDev, TRUE ); +done: if(glyphs != wstr) HeapFree(GetProcessHeap(), 0, (WORD*)glyphs); return retv; } -- 2.11.4.GIT