hhctrl.ocx: Handle memory allocation in OpenCHM and CloseCHM.

This commit is contained in:
Jacek Caban 2007-02-23 03:30:38 +01:00 committed by Alexandre Julliard
parent 976f2db58d
commit 1711c3a5c4
3 changed files with 46 additions and 33 deletions

View File

@ -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; i<pCHMInfo->strings_size; i++)
hhctrl_free(pCHMInfo->strings[i]);
for(i=0; i<chm->strings_size; i++)
hhctrl_free(chm->strings[i]);
}
hhctrl_free(pCHMInfo->strings);
hhctrl_free(chm->strings);
hhctrl_free(chm);
return NULL;
}

View File

@ -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;
}

View File

@ -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 */