hhctrl.ocx: Use wrappers of memory allocation functions.

oldstable
Jacek Caban 2007-02-22 22:49:13 +01:00 committed by Alexandre Julliard
parent 5faa1f6b1e
commit 07ba45775c
5 changed files with 55 additions and 34 deletions

View File

@ -36,7 +36,7 @@ static LPWSTR CHM_ReadString(CHMInfo *pChmInfo, DWORD dwOffset)
static const WCHAR stringsW[] = {'#','S','T','R','I','N','G','S',0}; static const WCHAR stringsW[] = {'#','S','T','R','I','N','G','S',0};
dwSize = CB_READ_BLOCK; dwSize = CB_READ_BLOCK;
szString = HeapAlloc(GetProcessHeap(), 0, dwSize); szString = hhctrl_alloc(dwSize);
if (FAILED(IStorage_OpenStream(pStorage, stringsW, NULL, STGM_READ, 0, &pStream))) if (FAILED(IStorage_OpenStream(pStorage, stringsW, NULL, STGM_READ, 0, &pStream)))
return NULL; return NULL;
@ -59,13 +59,13 @@ static LPWSTR CHM_ReadString(CHMInfo *pChmInfo, DWORD dwOffset)
if (!szString[iPos]) if (!szString[iPos])
{ {
stringW = strdupAtoW(szString); stringW = strdupAtoW(szString);
HeapFree(GetProcessHeap(), 0, szString); hhctrl_free(szString);
return stringW; return stringW;
} }
} }
dwSize *= 2; dwSize *= 2;
szString = HeapReAlloc(GetProcessHeap(), 0, szString, dwSize); szString = hhctrl_realloc(szString, dwSize);
szString += cbRead; szString += cbRead;
} }

View File

@ -66,7 +66,7 @@ static LPWSTR HH_LoadString(DWORD dwID)
iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0); iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
iSize += 2; /* some strings (tab text) needs double-null termination */ 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); LoadStringW(hhctrl_hinstance, dwID, string, iSize);
return string; return string;
@ -457,7 +457,7 @@ static BOOL HH_AddToolbar(HHInfo *pHHInfo)
szBuf[dwLen + 2] = 0; /* Double-null terminate */ szBuf[dwLen + 2] = 0; /* Double-null terminate */
buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf); 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); 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; tie.pszText = tabText;
SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie ); SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
HeapFree(GetProcessHeap(), 0, tabText); hhctrl_free(tabText);
} }
static BOOL HH_AddNavigationPane(HHInfo *pHHInfo) static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
@ -782,11 +782,11 @@ static BOOL HH_CreateViewer(HHInfo *pHHInfo)
static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPWSTR szCmdLine) 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->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW));
pHHInfo->pCHMInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo)); pHHInfo->pCHMInfo = hhctrl_alloc(sizeof(CHMInfo));
pHHInfo->pWBInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo)); pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
pHHInfo->hInstance = hInstance; pHHInfo->hInstance = hInstance;
pHHInfo->szCmdLine = szCmdLine; pHHInfo->szCmdLine = szCmdLine;
@ -801,31 +801,31 @@ static void HH_Close(HHInfo *pHHInfo)
/* Free allocated strings */ /* Free allocated strings */
if (pHHInfo->pHHWinType) if (pHHInfo->pHHWinType)
{ {
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszType);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszCaption); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszCaption);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszToc); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszToc);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszIndex); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszIndex);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszFile); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszFile);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszHome); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszHome);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump1); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump1);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump2); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump2);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump1); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump2); hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
} }
HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType); hhctrl_free(pHHInfo->pHHWinType);
HeapFree(GetProcessHeap(), 0, pHHInfo->szCmdLine); hhctrl_free(pHHInfo->szCmdLine);
if (pHHInfo->pCHMInfo) if (pHHInfo->pCHMInfo)
{ {
CHM_CloseCHM(pHHInfo->pCHMInfo); CHM_CloseCHM(pHHInfo->pCHMInfo);
HeapFree(GetProcessHeap(), 0, pHHInfo->pCHMInfo); hhctrl_free(pHHInfo->pCHMInfo);
} }
if (pHHInfo->pWBInfo) if (pHHInfo->pWBInfo)
{ {
WB_UnEmbedBrowser(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); HH_Close(pHHInfo);
HeapFree(GetProcessHeap(), 0, pHHInfo); hhctrl_free(pHHInfo);
OleUninitialize(); OleUninitialize();
return 0; return 0;

View File

@ -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 ); 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 ); 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: default:
FIXME("HH case %s not handled.\n", command_to_string( command )); FIXME("HH case %s not handled.\n", command_to_string( command ));
} }
HeapFree(GetProcessHeap(), 0, file); hhctrl_free(file);
return 0; 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 ); 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 ); MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
} }
result = HtmlHelpW( caller, wfile, command, data ); result = HtmlHelpW( caller, wfile, command, data );
HeapFree( GetProcessHeap(), 0, wfile ); hhctrl_free(wfile);
return result; return result;
} }

View File

@ -70,6 +70,28 @@ BOOL CHM_OpenCHM(CHMInfo *pCHMInfo, LPCWSTR szFile);
BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType); BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
void CHM_CloseCHM(CHMInfo *pCHMInfo); 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) static inline LPWSTR strdupAtoW(LPCSTR str)
{ {
LPWSTR ret; LPWSTR ret;
@ -79,7 +101,7 @@ static inline LPWSTR strdupAtoW(LPCSTR str)
return NULL; return NULL;
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); 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); MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
return ret; return ret;

View File

@ -74,7 +74,7 @@ static ULONG STDMETHODCALLTYPE Site_Release(IOleClientSite *iface)
if (refCount) if (refCount)
return refCount; return refCount;
HeapFree(GetProcessHeap(), 0, This); hhctrl_free(This);
return 0; return 0;
} }
@ -579,8 +579,7 @@ BOOL WB_EmbedBrowser(WBInfo *pWBInfo, HWND hwndParent)
/* clear out struct to keep from accessing invalid ptrs */ /* clear out struct to keep from accessing invalid ptrs */
ZeroMemory(pWBInfo, sizeof(WBInfo)); ZeroMemory(pWBInfo, sizeof(WBInfo));
iOleClientSiteImpl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iOleClientSiteImpl = hhctrl_alloc_zero(sizeof(IOleClientSiteImpl));
sizeof(IOleClientSiteImpl));
if (!iOleClientSiteImpl) if (!iOleClientSiteImpl)
return FALSE; return FALSE;
@ -631,7 +630,7 @@ BOOL WB_EmbedBrowser(WBInfo *pWBInfo, HWND hwndParent)
error: error:
WB_UnEmbedBrowser(pWBInfo); WB_UnEmbedBrowser(pWBInfo);
HeapFree(GetProcessHeap(), 0, iOleClientSiteImpl); hhctrl_free(iOleClientSiteImpl);
return FALSE; return FALSE;
} }