Commit 1711c3a5 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

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

parent 976f2db5
......@@ -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 #STRINGS stream: %08x\n", hres);
return FALSE;
WARN("Could not open storage: %08x\n", hres);
return CloseCHM(ret);
}
pChmInfo->strings = NULL;
pChmInfo->strings_size = 0;
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 CloseCHM(ret);
}
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;
}
......@@ -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;
}
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment