Jacek Caban : hhctrl.ocx: Use wrappers of memory allocation functions.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Feb 23 05:28:20 CST 2007


Module: wine
Branch: master
Commit: 07ba45775cc071b325208922d234cb0bdb09db9e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=07ba45775cc071b325208922d234cb0bdb09db9e

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Feb 22 22:49:13 2007 +0100

hhctrl.ocx: Use wrappers of memory allocation functions.

---

 dlls/hhctrl.ocx/chm.c        |    6 ++--
 dlls/hhctrl.ocx/help.c       |   44 +++++++++++++++++++++---------------------
 dlls/hhctrl.ocx/hhctrl.c     |    8 +++---
 dlls/hhctrl.ocx/hhctrl.h     |   24 +++++++++++++++++++++-
 dlls/hhctrl.ocx/webbrowser.c |    7 ++---
 5 files changed, 55 insertions(+), 34 deletions(-)

diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c
index 3e105b0..2fad67c 100644
--- a/dlls/hhctrl.ocx/chm.c
+++ b/dlls/hhctrl.ocx/chm.c
@@ -36,7 +36,7 @@ static LPWSTR CHM_ReadString(CHMInfo *pChmInfo, DWORD dwOffset)
     static const WCHAR stringsW[] = {'#','S','T','R','I','N','G','S',0};
 
     dwSize = CB_READ_BLOCK;
-    szString = HeapAlloc(GetProcessHeap(), 0, dwSize);
+    szString = hhctrl_alloc(dwSize);
 
     if (FAILED(IStorage_OpenStream(pStorage, stringsW, NULL, STGM_READ, 0, &pStream)))
         return NULL;
@@ -59,13 +59,13 @@ static LPWSTR CHM_ReadString(CHMInfo *pChmInfo, DWORD dwOffset)
             if (!szString[iPos])
             {
                 stringW = strdupAtoW(szString);
-                HeapFree(GetProcessHeap(), 0, szString);
+                hhctrl_free(szString);
                 return stringW;
             }
         }
 
         dwSize *= 2;
-        szString = HeapReAlloc(GetProcessHeap(), 0, szString, dwSize);
+        szString = hhctrl_realloc(szString, dwSize);
         szString += cbRead;
     }
 
diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c
index 39d750b..cfb4b90 100644
--- a/dlls/hhctrl.ocx/help.c
+++ b/dlls/hhctrl.ocx/help.c
@@ -66,7 +66,7 @@ static LPWSTR HH_LoadString(DWORD dwID)
     iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
     iSize += 2; /* some strings (tab text) needs double-null termination */
 
-    string = HeapAlloc(GetProcessHeap(), 0, iSize * sizeof(WCHAR));
+    string = hhctrl_alloc(iSize * sizeof(WCHAR));
     LoadStringW(hhctrl_hinstance, dwID, string, iSize);
 
     return string;
@@ -457,7 +457,7 @@ static BOOL HH_AddToolbar(HHInfo *pHHInfo)
         szBuf[dwLen + 2] = 0; /* Double-null terminate */
 
         buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
-        HeapFree(GetProcessHeap(), 0, szBuf);
+        hhctrl_free(szBuf);
     }
 
     SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
@@ -504,7 +504,7 @@ static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, D
     tie.pszText = tabText;
 
     SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
-    HeapFree(GetProcessHeap(), 0, tabText);
+    hhctrl_free(tabText);
 }
 
 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
@@ -782,11 +782,11 @@ static BOOL HH_CreateViewer(HHInfo *pHHInfo)
 
 static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPWSTR szCmdLine)
 {
-    HHInfo *pHHInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HHInfo));
+    HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
 
-    pHHInfo->pHHWinType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HH_WINTYPEW));
-    pHHInfo->pCHMInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo));
-    pHHInfo->pWBInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo));
+    pHHInfo->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW));
+    pHHInfo->pCHMInfo = hhctrl_alloc(sizeof(CHMInfo));
+    pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
     pHHInfo->hInstance = hInstance;
     pHHInfo->szCmdLine = szCmdLine;
 
@@ -801,31 +801,31 @@ static void HH_Close(HHInfo *pHHInfo)
     /* Free allocated strings */
     if (pHHInfo->pHHWinType)
     {
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszCaption);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszToc);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszIndex);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszFile);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszHome);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump1);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump2);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
-        HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszType);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszCaption);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszToc);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszIndex);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszFile);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszHome);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump1);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump2);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
+        hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
     }
 
-    HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType);
-    HeapFree(GetProcessHeap(), 0, pHHInfo->szCmdLine);
+    hhctrl_free(pHHInfo->pHHWinType);
+    hhctrl_free(pHHInfo->szCmdLine);
 
     if (pHHInfo->pCHMInfo)
     {
         CHM_CloseCHM(pHHInfo->pCHMInfo);
-        HeapFree(GetProcessHeap(), 0, pHHInfo->pCHMInfo);
+        hhctrl_free(pHHInfo->pCHMInfo);
     }
 
     if (pHHInfo->pWBInfo)
     {
         WB_UnEmbedBrowser(pHHInfo->pWBInfo);
-        HeapFree(GetProcessHeap(), 0, pHHInfo->pWBInfo);
+        hhctrl_free(pHHInfo->pWBInfo);
     }
 }
 
@@ -865,7 +865,7 @@ int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
     }
 
     HH_Close(pHHInfo);
-    HeapFree(GetProcessHeap(), 0, pHHInfo);
+    hhctrl_free(pHHInfo);
     OleUninitialize();
 
     return 0;
diff --git a/dlls/hhctrl.ocx/hhctrl.c b/dlls/hhctrl.ocx/hhctrl.c
index 445438d..18e769f 100644
--- a/dlls/hhctrl.ocx/hhctrl.c
+++ b/dlls/hhctrl.ocx/hhctrl.c
@@ -97,7 +97,7 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD data)
     {
         DWORD len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
 
-        file = HeapAlloc( GetProcessHeap(), 0, len );
+        file = hhctrl_alloc(len);
         WideCharToMultiByte( CP_ACP, 0, filename, -1, file, len, NULL, NULL );
     }
 
@@ -113,7 +113,7 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD data)
         default:
             FIXME("HH case %s not handled.\n", command_to_string( command ));
     }
-    HeapFree(GetProcessHeap(), 0, file);
+    hhctrl_free(file);
     return 0;
 }
 
@@ -126,12 +126,12 @@ HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD data)
     {
         DWORD len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
 
-        wfile = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
+        wfile = hhctrl_alloc(len*sizeof(WCHAR));
         MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
     }
 
     result = HtmlHelpW( caller, wfile, command, data );
 
-    HeapFree( GetProcessHeap(), 0, wfile );
+    hhctrl_free(wfile);
     return result;
 }
diff --git a/dlls/hhctrl.ocx/hhctrl.h b/dlls/hhctrl.ocx/hhctrl.h
index 367564b..4257687 100644
--- a/dlls/hhctrl.ocx/hhctrl.h
+++ b/dlls/hhctrl.ocx/hhctrl.h
@@ -70,6 +70,28 @@ BOOL CHM_OpenCHM(CHMInfo *pCHMInfo, LPCWSTR szFile);
 BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
 void CHM_CloseCHM(CHMInfo *pCHMInfo);
 
+/* memory allocation functions */
+
+static inline void *hhctrl_alloc(size_t len)
+{
+    return HeapAlloc(GetProcessHeap(), 0, len);
+}
+
+static inline void *hhctrl_alloc_zero(size_t len)
+{
+    return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
+}
+
+static inline void *hhctrl_realloc(void *mem, size_t len)
+{
+    return HeapReAlloc(GetProcessHeap(), 0, mem, len);
+}
+
+static inline BOOL hhctrl_free(void *mem)
+{
+    return HeapFree(GetProcessHeap(), 0, mem);
+}
+
 static inline LPWSTR strdupAtoW(LPCSTR str)
 {
     LPWSTR ret;
@@ -79,7 +101,7 @@ static inline LPWSTR strdupAtoW(LPCSTR str)
         return NULL;
 
     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
-    ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
+    ret = hhctrl_alloc(len*sizeof(WCHAR));
     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
 
     return ret;
diff --git a/dlls/hhctrl.ocx/webbrowser.c b/dlls/hhctrl.ocx/webbrowser.c
index 4babc64..bf3b65b 100644
--- a/dlls/hhctrl.ocx/webbrowser.c
+++ b/dlls/hhctrl.ocx/webbrowser.c
@@ -74,7 +74,7 @@ static ULONG STDMETHODCALLTYPE Site_Release(IOleClientSite *iface)
     if (refCount)
         return refCount;
 
-    HeapFree(GetProcessHeap(), 0, This);
+    hhctrl_free(This);
     return 0;
 }
 
@@ -579,8 +579,7 @@ BOOL WB_EmbedBrowser(WBInfo *pWBInfo, HWND hwndParent)
     /* clear out struct to keep from accessing invalid ptrs */
     ZeroMemory(pWBInfo, sizeof(WBInfo));
 
-    iOleClientSiteImpl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-                                   sizeof(IOleClientSiteImpl));
+    iOleClientSiteImpl = hhctrl_alloc_zero(sizeof(IOleClientSiteImpl));
     if (!iOleClientSiteImpl)
         return FALSE;
 
@@ -631,7 +630,7 @@ BOOL WB_EmbedBrowser(WBInfo *pWBInfo, HWND hwndParent)
 
 error:
     WB_UnEmbedBrowser(pWBInfo);
-    HeapFree(GetProcessHeap(), 0, iOleClientSiteImpl);
+    hhctrl_free(iOleClientSiteImpl);
 
     return FALSE;
 }




More information about the wine-cvs mailing list