From 001a936176d1a21c131516fa319f49e0dc5e7a73 Mon Sep 17 00:00:00 2001 From: Peter Berg Larsen Date: Fri, 11 Mar 2005 12:50:27 +0000 Subject: [PATCH] Assorted memleak fixes. Found on Michael Stefaniuc smatch list. --- dlls/winmm/driver.c | 11 ++++++----- dlls/winmm/mmio.c | 7 ++++--- dlls/winmm/mmsystem.c | 13 ++++++++----- dlls/winmm/time.c | 6 +++--- dlls/wsock32/socket.c | 16 ++++++++++++---- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/dlls/winmm/driver.c b/dlls/winmm/driver.c index c4a52a5c7e5..f2123b353b7 100644 --- a/dlls/winmm/driver.c +++ b/dlls/winmm/driver.c @@ -308,13 +308,13 @@ HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lPara 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 done; MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len ); } @@ -322,14 +322,15 @@ HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lPara { len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 ); sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); - if (!sn) return 0; + if (!sn) goto done; MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len ); } ret = OpenDriver(dn, sn, lParam); - if (dn) HeapFree(GetProcessHeap(), 0, dn); - if (sn) HeapFree(GetProcessHeap(), 0, sn); +done: + HeapFree(GetProcessHeap(), 0, dn); + HeapFree(GetProcessHeap(), 0, sn); return ret; } diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c index ba446069070..6019821566d 100644 --- a/dlls/winmm/mmio.c +++ b/dlls/winmm/mmio.c @@ -1360,26 +1360,27 @@ MMRESULT WINAPI mmioRenameW(LPCWSTR szFileName, LPCWSTR szNewFileName, { 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 done; 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 done; WideCharToMultiByte( CP_ACP, 0, szNewFileName, -1, sznFn, len, NULL, NULL ); } ret = mmioRenameA(szFn, sznFn, lpmmioinfo, dwFlags); +done: HeapFree(GetProcessHeap(),0,szFn); HeapFree(GetProcessHeap(),0,sznFn); return ret; diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c index 3fd754f29b8..e12b0282a8b 100644 --- a/dlls/winmm/mmsystem.c +++ b/dlls/winmm/mmsystem.c @@ -2260,7 +2260,7 @@ static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lPara LPDRVCONFIGINFO dci32 = (LPDRVCONFIGINFO)(*lParam2); if (dci16) { - LPSTR str1; + LPSTR str1 = NULL,str2; INT len; dci16->dwDCISize = sizeof(DRVCONFIGINFO16); @@ -2271,6 +2271,7 @@ static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lPara 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 @@ static WINMM_MapType DRIVER_MapMsg32To16(WORD wMsg, DWORD* lParam1, DWORD* lPara } 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 { + HeapFree( GetProcessHeap(), 0, str1); + HeapFree( GetProcessHeap(), 0, dci16); return WINMM_MAP_NOMEM; } } else { diff --git a/dlls/winmm/time.c b/dlls/winmm/time.c index a1960ce919d..3b99845aa72 100644 --- a/dlls/winmm/time.c +++ b/dlls/winmm/time.c @@ -315,11 +315,11 @@ WORD TIME_SetEventInternal(UINT wDelay, UINT wResol, 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 = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_TIMERENTRY)); + if (lpNewTimer == NULL) return 0; TIME_MMTimeStart(); diff --git a/dlls/wsock32/socket.c b/dlls/wsock32/socket.c index 8d9b8a89476..8df93755bb2 100644 --- a/dlls/wsock32/socket.c +++ b/dlls/wsock32/socket.c @@ -436,7 +436,7 @@ DWORD WINAPI WsControl(DWORD protocol, * interface are returned. */ case CL_NL_ENTITY: { - DWORD routeTableSize, numRoutes, ndx; + DWORD routeTableSize, numRoutes, ndx, ret; PMIB_IPFORWARDTABLE table; IPRouteEntry *winRouteTable = (IPRouteEntry *) pResponseInfo; @@ -450,7 +450,11 @@ DWORD WINAPI WsControl(DWORD protocol, table = (PMIB_IPFORWARDTABLE)calloc(1, routeTableSize); if (!table) return ERROR_NOT_ENOUGH_MEMORY; - GetIpForwardTable(table, &routeTableSize, FALSE); + ret = GetIpForwardTable(table, &routeTableSize, FALSE); + if (ret != NO_ERROR) { + free(table); + return ret; + } memset(pResponseInfo, 0, sizeof(IPRouteEntry) * numRoutes); for (ndx = 0; ndx < table->dwNumEntries; ndx++) @@ -496,8 +500,10 @@ DWORD WINAPI WsControl(DWORD protocol, if (!table) return ERROR_NOT_ENOUGH_MEMORY; ret = GetIpNetTable(table, &arpTableSize, FALSE); - if (ret != NO_ERROR) + if (ret != NO_ERROR) { + free(table); return ret; + } if (*pcbResponseInfoLen < sizeof(MIB_IPNETROW) * table->dwNumEntries) { @@ -532,8 +538,10 @@ DWORD WINAPI WsControl(DWORD protocol, if (!table) return ERROR_NOT_ENOUGH_MEMORY; ret = GetTcpTable(table, &tcpTableSize, FALSE); - if (ret != NO_ERROR) + if (ret != NO_ERROR) { + free(table); return ret; + } if (*pcbResponseInfoLen < sizeof(MIB_TCPROW) * table->dwNumEntries) { -- 2.11.4.GIT