Fix a memory leak in toolbar
Dimitrie O. Paun
dpaun at rogers.com
Thu Mar 24 19:25:22 CST 2005
ChangeLog
Fix a memory leak in toolbar. Avoid casts.
Index: dlls/comctl32/toolbar.c
===================================================================
RCS file: /var/cvs/wine/dlls/comctl32/toolbar.c,v
retrieving revision 1.209
diff -u -r1.209 toolbar.c
--- dlls/comctl32/toolbar.c 23 Mar 2005 10:24:06 -0000 1.209
+++ dlls/comctl32/toolbar.c 25 Mar 2005 01:23:00 -0000
@@ -4527,23 +4527,33 @@
static LRESULT
TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
{
+ LPWSTR pszValueName = 0, pszSubKey = 0;
TBSAVEPARAMSW SaveW;
+ LRESULT result = 0;
int len;
if (lpSave == NULL) return 0;
- SaveW.hkr = lpSave->hkr;
-
len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
- SaveW.pszSubKey = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
- MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, (LPWSTR)SaveW.pszSubKey, len);
+ pszSubKey = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ if (pszSubKey) goto exit;
+ MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
- SaveW.pszValueName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
- MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, (LPWSTR)SaveW.pszValueName, len);
+ pszValueName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ if (!pszValueName) goto exit;
+ MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
+
+ SaveW.pszValueName = pszValueName;
+ SaveW.pszSubKey = pszSubKey;
+ SaveW.hkr = lpSave->hkr;
+ result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
+
+exit:
+ HeapFree(GetProcessHeap(), 0, pszValueName);
+ HeapFree(GetProcessHeap(), 0, pszSubKey);
- /* FIXME: shoudn't we free the HeapAlloc()ed memory? */
- return TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
+ return result;
}
--
Dimi.
More information about the wine-patches
mailing list