From 1711c3a5c473d5b011e67f32a25b7fad9645df73 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 23 Feb 2007 03:30:38 +0100 Subject: [PATCH] hhctrl.ocx: Handle memory allocation in OpenCHM and CloseCHM. --- dlls/hhctrl.ocx/chm.c | 60 ++++++++++++++++++++++++---------------- dlls/hhctrl.ocx/help.c | 15 +++++----- dlls/hhctrl.ocx/hhctrl.h | 4 +-- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c index 9fc98c60387..83599a17f96 100644 --- a/dlls/hhctrl.ocx/chm.c +++ b/dlls/hhctrl.ocx/chm.c @@ -127,48 +127,60 @@ done: } /* Opens the CHM file for reading */ -BOOL CHM_OpenCHM(CHMInfo *pChmInfo, LPCWSTR szFile) +CHMInfo *OpenCHM(LPCWSTR szFile) { HRESULT hres; static const WCHAR wszSTRINGS[] = {'#','S','T','R','I','N','G','S',0}; - pChmInfo->szFile = szFile; + CHMInfo *ret = hhctrl_alloc_zero(sizeof(CHMInfo)); - if (FAILED(CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER, - &IID_IITStorage, (void **) &pChmInfo->pITStorage))) - return FALSE; + ret->szFile = szFile; - if (FAILED(IITStorage_StgOpenStorage(pChmInfo->pITStorage, szFile, NULL, - STGM_READ | STGM_SHARE_DENY_WRITE, - NULL, 0, &pChmInfo->pStorage))) - return FALSE; + hres = CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER, + &IID_IITStorage, (void **) &ret->pITStorage) ; + if(FAILED(hres)) { + WARN("Could not create ITStorage: %08x\n", hres); + return CloseCHM(ret); + } - hres = IStorage_OpenStream(pChmInfo->pStorage, wszSTRINGS, NULL, STGM_READ, 0, - &pChmInfo->strings_stream); + hres = IITStorage_StgOpenStorage(ret->pITStorage, szFile, NULL, + STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &ret->pStorage); + if(FAILED(hres)) { + WARN("Could not open storage: %08x\n", hres); + return CloseCHM(ret); + } + + hres = IStorage_OpenStream(ret->pStorage, wszSTRINGS, NULL, STGM_READ, 0, + &ret->strings_stream); if(FAILED(hres)) { WARN("Could not open #STRINGS stream: %08x\n", hres); - return FALSE; + return CloseCHM(ret); } - pChmInfo->strings = NULL; - pChmInfo->strings_size = 0; - - return TRUE; + return ret; } -void CHM_CloseCHM(CHMInfo *pCHMInfo) +CHMInfo *CloseCHM(CHMInfo *chm) { - IITStorage_Release(pCHMInfo->pITStorage); - IStorage_Release(pCHMInfo->pStorage); - IStream_Release(pCHMInfo->strings_stream); + if(chm->pITStorage) + IITStorage_Release(chm->pITStorage); - if(pCHMInfo->strings_size) { + if(chm->pStorage) + IStorage_Release(chm->pStorage); + + if(chm->strings_stream) + IStream_Release(chm->strings_stream); + + if(chm->strings_size) { int i; - for(i=0; istrings_size; i++) - hhctrl_free(pCHMInfo->strings[i]); + for(i=0; istrings_size; i++) + hhctrl_free(chm->strings[i]); } - hhctrl_free(pCHMInfo->strings); + hhctrl_free(chm->strings); + hhctrl_free(chm); + + return NULL; } diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c index 0e5d4bd12d7..e018c147a51 100644 --- a/dlls/hhctrl.ocx/help.c +++ b/dlls/hhctrl.ocx/help.c @@ -800,10 +800,7 @@ static void HH_Close(HHInfo *pHHInfo) hhctrl_free(pHHInfo->pHHWinType); if (pHHInfo->pCHMInfo) - { - CHM_CloseCHM(pHHInfo->pCHMInfo); - hhctrl_free(pHHInfo->pCHMInfo); - } + CloseCHM(pHHInfo->pCHMInfo); if (pHHInfo->pWBInfo) { @@ -816,12 +813,16 @@ static HHInfo *HH_OpenHH(LPWSTR filename) { HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo)); + pHHInfo->pCHMInfo = OpenCHM(filename); + if(!pHHInfo->pCHMInfo) { + HH_Close(pHHInfo); + return NULL; + } + pHHInfo->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW)); - pHHInfo->pCHMInfo = hhctrl_alloc(sizeof(CHMInfo)); pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo)); - if (!CHM_OpenCHM(pHHInfo->pCHMInfo, filename) - || !CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType)) { + if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType)) { HH_Close(pHHInfo); return NULL; } diff --git a/dlls/hhctrl.ocx/hhctrl.h b/dlls/hhctrl.ocx/hhctrl.h index 355fc02f796..23803b1e0e0 100644 --- a/dlls/hhctrl.ocx/hhctrl.h +++ b/dlls/hhctrl.ocx/hhctrl.h @@ -70,9 +70,9 @@ void WB_UnEmbedBrowser(WBInfo *pWBInfo); void WB_ResizeBrowser(WBInfo *pWBInfo, DWORD dwWidth, DWORD dwHeight); void WB_DoPageAction(WBInfo *pWBInfo, DWORD dwAction); -BOOL CHM_OpenCHM(CHMInfo *pCHMInfo, LPCWSTR szFile); +CHMInfo *OpenCHM(LPCWSTR szFile); BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType); -void CHM_CloseCHM(CHMInfo *pCHMInfo); +CHMInfo *CloseCHM(CHMInfo *pCHMInfo); /* memory allocation functions */