[x11drv] Memleak fixes in x11drv/* errorpaths

Peter Berg Larsen pebl at math.ku.dk
Thu Mar 10 16:13:39 CST 2005


Changelog:
	Assorted memleak fixes in x11drv/*.
	Found on Michael Stefaniuc smatch list.



Index: dlls/x11drv/clipboard.c
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/clipboard.c,v
retrieving revision 1.36
diff -u -r1.36 clipboard.c
--- dlls/x11drv/clipboard.c	7 Mar 2005 19:31:47 -0000	1.36
+++ dlls/x11drv/clipboard.c	9 Mar 2005 23:51:35 -0000
@@ -1256,19 +1256,23 @@
 HANDLE X11DRV_CLIPBOARD_ImportClipboardData(LPBYTE lpdata, UINT cBytes)
 {
     LPVOID lpClipData;
-    HANDLE hClipData = 0;
+    HANDLE hClipData = NULL;

     if (cBytes)
     {
         /* Turn on the DDESHARE flag to enable shared 32 bit memory */
         hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes);
+	if (hClipData == NULL) return NULL;
+
         if ((lpClipData = GlobalLock(hClipData)))
         {
             memcpy(lpClipData, lpdata, cBytes);
             GlobalUnlock(hClipData);
         }
-        else
-            hClipData = 0;
+        else {
+            GlobalFree(hClipData);
+            hClipData = NULL;
+	}
     }

     return hClipData;
@@ -1285,7 +1289,7 @@
 {
     LPVOID lpClipData;
     UINT cBytes = 0;
-    HANDLE hClipData = 0;
+    HANDLE hClipData = NULL;

     *lpBytes = 0; /* Assume failure */

@@ -1296,6 +1300,7 @@
         cBytes = GlobalSize(lpData->hData32);

         hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes);
+	if (hClipData == NULL) return NULL;

         if ((lpClipData = GlobalLock(hClipData)))
         {
@@ -1306,7 +1311,10 @@

             GlobalUnlock(lpData->hData32);
             GlobalUnlock(hClipData);
-        }
+        } else {
+	    GlobalFree(hClipData);
+    	    hClipData = NULL;
+	}
     }

     return hClipData;
@@ -1324,7 +1332,7 @@
     UINT i, j;
     UINT size;
     LPWSTR uni_text;
-    LPSTR text, lpstr;
+    LPSTR text, lpstr = None;

     *lpBytes = 0; /* Assume return has zero bytes */

@@ -1333,14 +1341,16 @@
     size = WideCharToMultiByte(CP_UNIXCP, 0, uni_text, -1, NULL, 0, NULL, NULL);

     text = HeapAlloc(GetProcessHeap(), 0, size);
-    if (!text)
-       return None;
+    if (!text) goto err;
     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) {
+	    lpstr = None;
+	    goto err_text;
+    }
     for(i = 0,j = 0; i < size && text[i]; i++ )
     {
         if( text[i] == '\r' &&
@@ -1351,7 +1361,9 @@

     *lpBytes = j; /* Number of bytes in string */

+err_text:
     HeapFree(GetProcessHeap(), 0, text);
+err:
     GlobalUnlock(lpData->hData32);

     return lpstr;
Index: dlls/x11drv/xrender.c
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/xrender.c,v
retrieving revision 1.58
diff -u -r1.58 xrender.c
--- dlls/x11drv/xrender.c	23 Feb 2005 12:42:17 -0000	1.58
+++ dlls/x11drv/xrender.c	9 Mar 2005 23:52:33 -0000
@@ -1065,13 +1065,13 @@

     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 @@

     if(count == 0) {
 	retv =  TRUE;
-        goto done;
+        goto done_unlock;
     }

     pt.x = x;
@@ -1539,7 +1539,7 @@
             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 @@

     retv = TRUE;

-done:
+done_unlock:
     X11DRV_UnlockDIBSection( physDev, TRUE );
+done:
     if(glyphs != wstr) HeapFree(GetProcessHeap(), 0, (WORD*)glyphs);
     return retv;
 }




More information about the wine-patches mailing list