[winmm] Memleak fixes in winmm/* error paths.

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


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


Index: dlls/winmm/driver.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/driver.c,v
retrieving revision 1.30
diff -u -r1.30 driver.c
--- dlls/winmm/driver.c	9 Feb 2005 22:26:26 -0000	1.30
+++ dlls/winmm/driver.c	10 Mar 2005 00:58:13 -0000
@@ -308,13 +308,13 @@
     INT                 len;
     LPWSTR 		dn = NULL;
     LPWSTR 		sn = NULL;
-    HDRVR		ret;
+    HDRVR		ret = 0;

     if (lpDriverName)
     {
         len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
         dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
-        if (!dn) return 0;
+        if (!dn) goto err;
         MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
     }

@@ -322,12 +322,13 @@
     {
         len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
         sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
-        if (!sn) return 0;
+        if (!sn) goto err;
         MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
     }

     ret = OpenDriver(dn, sn, lParam);

+err:
     if (dn) HeapFree(GetProcessHeap(), 0, dn);
     if (sn) HeapFree(GetProcessHeap(), 0, sn);
     return ret;
Index: dlls/winmm/mmio.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/mmio.c,v
retrieving revision 1.47
diff -u -r1.47 mmio.c
--- dlls/winmm/mmio.c	9 Feb 2005 22:26:26 -0000	1.47
+++ dlls/winmm/mmio.c	10 Mar 2005 00:58:32 -0000
@@ -1360,26 +1360,27 @@
 {
     LPSTR	szFn = NULL;
     LPSTR	sznFn = NULL;
-    UINT	ret;
+    UINT	ret = MMSYSERR_NOMEM;
     INT         len;

     if (szFileName)
     {
         len = WideCharToMultiByte( CP_ACP, 0, szFileName, -1, NULL, 0, NULL, NULL );
         szFn = HeapAlloc( GetProcessHeap(), 0, len );
-        if (!szFn) return MMSYSERR_NOMEM;
+        if (!szFn) goto err;
         WideCharToMultiByte( CP_ACP, 0, szFileName, -1, szFn, len, NULL, NULL );
     }
     if (szNewFileName)
     {
         len = WideCharToMultiByte( CP_ACP, 0, szNewFileName, -1, NULL, 0, NULL, NULL );
         sznFn = HeapAlloc( GetProcessHeap(), 0, len );
-        if (!sznFn) return MMSYSERR_NOMEM;
+        if (!sznFn) goto err;
         WideCharToMultiByte( CP_ACP, 0, szNewFileName, -1, sznFn, len, NULL, NULL );
     }

     ret = mmioRenameA(szFn, sznFn, lpmmioinfo, dwFlags);

+err:
     HeapFree(GetProcessHeap(),0,szFn);
     HeapFree(GetProcessHeap(),0,sznFn);
     return ret;
Index: dlls/winmm/mmsystem.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/mmsystem.c,v
retrieving revision 1.112
diff -u -r1.112 mmsystem.c
--- dlls/winmm/mmsystem.c	9 Feb 2005 22:26:26 -0000	1.112
+++ dlls/winmm/mmsystem.c	10 Mar 2005 00:59:02 -0000
@@ -2260,7 +2260,7 @@
             LPDRVCONFIGINFO	dci32 = (LPDRVCONFIGINFO)(*lParam2);

 	    if (dci16) {
-		LPSTR str1;
+		LPSTR str1 = NULL,str2;
                 INT len;
 		dci16->dwDCISize = sizeof(DRVCONFIGINFO16);

@@ -2271,6 +2271,7 @@
                         WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCISectionName, -1, str1, len, NULL, NULL );
                         dci16->lpszDCISectionName = MapLS( str1 );
                     } else {
+                        HeapFree( GetProcessHeap(), 0, dci16);
                         return WINMM_MAP_NOMEM;
                     }
 		} else {
@@ -2278,11 +2279,13 @@
 		}
                 if (dci32->lpszDCIAliasName) {
                     len = WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, NULL, 0, NULL, NULL );
-                    str1 = HeapAlloc( GetProcessHeap(), 0, len );
-                    if (str1) {
-                        WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, str1, len, NULL, NULL );
-                        dci16->lpszDCIAliasName = MapLS( str1 );
+                    str2 = HeapAlloc( GetProcessHeap(), 0, len );
+                    if (str2) {
+                        WideCharToMultiByte( CP_ACP, 0, dci32->lpszDCIAliasName, -1, str2, len, NULL, NULL );
+                        dci16->lpszDCIAliasName = MapLS( str2 );
                     } else {
+                        if (str1 != NULL) HeapFree( GetProcessHeap(), 0, str1);
+                        HeapFree( GetProcessHeap(), 0, dci16);
                         return WINMM_MAP_NOMEM;
                     }
 		} else {
Index: dlls/winmm/time.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/time.c,v
retrieving revision 1.29
diff -u -r1.29 time.c
--- dlls/winmm/time.c	14 Feb 2005 11:00:59 -0000	1.29
+++ dlls/winmm/time.c	10 Mar 2005 00:59:04 -0000
@@ -315,11 +315,11 @@

     TRACE("(%u, %u, %p, %08lX, %04X);\n", wDelay, wResol, lpFunc, dwUser, wFlags);

-    lpNewTimer = (LPWINE_TIMERENTRY)HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_TIMERENTRY));
-    if (lpNewTimer == NULL)
+    if (wDelay < MMSYSTIME_MININTERVAL || wDelay > MMSYSTIME_MAXINTERVAL)
 	return 0;

-    if (wDelay < MMSYSTIME_MININTERVAL || wDelay > MMSYSTIME_MAXINTERVAL)
+    lpNewTimer = (LPWINE_TIMERENTRY)HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_TIMERENTRY));
+    if (lpNewTimer == NULL)
 	return 0;

     TIME_MMTimeStart();






More information about the wine-patches mailing list