Commit cb782195 authored by Juergen Schmied's avatar Juergen Schmied Committed by Alexandre Julliard

Fixed crash during second DLL_PROCESS_DETACH if the dll

refcount reached zero after the second one (memory freed twice).
parent e80d3d7c
......@@ -446,9 +446,6 @@ end_1: _lclose( hFile);
}
/********************** THE ICON CACHE ********************************/
HIMAGELIST ShellSmallIconList = 0;
HIMAGELIST ShellBigIconList = 0;
HDPA hdpa=0;
#define INVALID_INDEX -1
......@@ -494,7 +491,7 @@ static INT SIC_IconAppend (LPCSTR sSourceFile, INT dwSourceIndex, HICON hSmallIc
lpsice->sSourceFile = HEAP_strdupA (GetProcessHeap(), 0, PathFindFilenameA(sSourceFile));
lpsice->dwSourceIndex = dwSourceIndex;
index = pDPA_InsertPtr(hdpa, 0x7fff, lpsice);
index = pDPA_InsertPtr(sic_hdpa, 0x7fff, lpsice);
if ( INVALID_INDEX == index )
{ SHFree(lpsice);
return INVALID_INDEX;
......@@ -551,8 +548,8 @@ INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
sice.sSourceFile = PathFindFilenameA(sSourceFile);
sice.dwSourceIndex = dwSourceIndex;
if (NULL != pDPA_GetPtr (hdpa, 0))
{ index = pDPA_Search (hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0);
if (NULL != pDPA_GetPtr (sic_hdpa, 0))
{ index = pDPA_Search (sic_hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0);
}
if ( INVALID_INDEX == index )
......@@ -560,7 +557,7 @@ INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
}
TRACE("-- found\n");
return ((LPSIC_ENTRY)pDPA_GetPtr(hdpa, index))->dwListIndex;
return ((LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, index))->dwListIndex;
}
/****************************************************************************
* SIC_LoadIcon [internal]
......@@ -598,12 +595,12 @@ BOOL SIC_Initialize(void)
TRACE("\n");
if (hdpa) /* already initialized?*/
if (sic_hdpa) /* already initialized?*/
return TRUE;
hdpa = pDPA_Create(16);
sic_hdpa = pDPA_Create(16);
if (!hdpa)
if (!sic_hdpa)
{ return(FALSE);
}
......@@ -652,13 +649,19 @@ void SIC_Destroy(void)
LPSIC_ENTRY lpsice;
int i;
if (hdpa && NULL != pDPA_GetPtr (hdpa, 0))
{ for (i=0; i < pDPA_GetPtrCount(hdpa); ++i)
{ lpsice = pDPA_GetPtr(hdpa, i);
TRACE("\n");
if (sic_hdpa && NULL != pDPA_GetPtr (sic_hdpa, 0))
{
for (i=0; i < pDPA_GetPtrCount(sic_hdpa); ++i)
{
lpsice = pDPA_GetPtr(sic_hdpa, i);
SHFree(lpsice);
}
pDPA_Destroy(hdpa);
pDPA_Destroy(sic_hdpa);
}
sic_hdpa = NULL;
}
/*************************************************************************
* Shell_GetImageList [SHELL32.71]
......
......@@ -416,7 +416,7 @@ DWORD WINAPI SHGetDesktopFolder(LPSHELLFOLDER *shellfolder)
{ hres = NOERROR;
}
else
{ lpclf = IClassFactory_Constructor();
{ lpclf = IClassFactory_Constructor(&CLSID_ShellDesktop);
if(lpclf)
{ hres = IClassFactory_CreateInstance(lpclf,NULL,(REFIID)&IID_IShellFolder, (void*)&pdesktopfolder);
IClassFactory_Release(lpclf);
......@@ -1058,6 +1058,7 @@ HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
}
/*************************************************************************
* global variables of the shell32.dll
* all are once per process
*
*/
void (WINAPI* pDLLInitComctl)(LPVOID);
......@@ -1089,6 +1090,11 @@ static INT shell32_RefCount = 0;
INT shell32_ObjCount = 0;
HINSTANCE shell32_hInstance;
HIMAGELIST ShellSmallIconList = 0;
HIMAGELIST ShellBigIconList = 0;
HDPA sic_hdpa = 0;
/*************************************************************************
* SHELL32 LibMain
*
......@@ -1102,12 +1108,16 @@ BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
shell32_hInstance = hinstDLL;
switch (fdwReason)
{ case DLL_PROCESS_ATTACH:
{
case DLL_PROCESS_ATTACH:
if (!bShell32IsInitialized)
{ hComctl32 = LoadLibraryA("COMCTL32.DLL");
{
hComctl32 = LoadLibraryA("COMCTL32.DLL");
hUser32 = GetModuleHandleA("USER32");
if (hComctl32 && hUser32)
{ pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
{
pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
if (pDLLInitComctl)
{ pDLLInitComctl(NULL);
}
......@@ -1158,10 +1168,11 @@ BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
if (pdesktopfolder)
{ IShellFolder_Release(pdesktopfolder);
pdesktopfolder = NULL;
}
SIC_Destroy();
FreeLibrary(hComctl32);
FreeLibrary(hComctl32);
/* this one is here to check if AddRef/Release is balanced */
if (shell32_ObjCount)
......
......@@ -22,8 +22,9 @@
*/
extern HINSTANCE shell32_hInstance;
extern INT shell32_ObjCount;
extern HIMAGELIST ShellSmallIconList;
extern HIMAGELIST ShellBigIconList;
extern HIMAGELIST ShellSmallIconList;
extern HIMAGELIST ShellBigIconList;
extern HDPA sic_hdpa;
/*******************************************
* pointer to functions dynamically loaded
......@@ -95,16 +96,13 @@ HANDLE WINAPI SHFreeShared(HANDLE hmem, DWORD procID);
extern LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPSHELLFOLDER psf, LPITEMIDLIST * apidl, UINT cidl);
extern LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT, const FORMATETC []);
extern LPCLASSFACTORY IShellLink_CF_Constructor(void);
extern LPCLASSFACTORY IShellLinkW_CF_Constructor(void);
extern LPCLASSFACTORY IClassFactory_Constructor(void);
extern LPCLASSFACTORY IClassFactory_Constructor(REFCLSID);
extern LPCONTEXTMENU IContextMenu_Constructor(LPSHELLFOLDER, LPCITEMIDLIST *, UINT);
extern LPSHELLVIEW IShellView_Constructor(LPSHELLFOLDER, LPCITEMIDLIST);
extern LPSHELLLINK IShellLink_Constructor(void);
extern LPSHELLLINKW IShellLinkW_Constructor(void);
extern LPSHELLLINK IShellLink_Constructor(BOOL);
extern LPENUMIDLIST IEnumIDList_Constructor(LPCSTR,DWORD);
extern LPEXTRACTICONA IExtractIconA_Constructor(LPITEMIDLIST);
extern HRESULT CreateStreamOnFile (LPCSTR pszFilename, IStream ** ppstm);
/* fixme: rename the functions when the shell32.dll has it's own exports namespace */
HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
......
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