Fixed crash during second DLL_PROCESS_DETACH if the dll

refcount reached zero after the second one (memory freed twice).
oldstable
Juergen Schmied 1999-07-10 11:50:54 +00:00 committed by Alexandre Julliard
parent e80d3d7c29
commit cb78219500
3 changed files with 39 additions and 27 deletions

View File

@ -446,9 +446,6 @@ end_1: _lclose( hFile);
} }
/********************** THE ICON CACHE ********************************/ /********************** THE ICON CACHE ********************************/
HIMAGELIST ShellSmallIconList = 0;
HIMAGELIST ShellBigIconList = 0;
HDPA hdpa=0;
#define INVALID_INDEX -1 #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->sSourceFile = HEAP_strdupA (GetProcessHeap(), 0, PathFindFilenameA(sSourceFile));
lpsice->dwSourceIndex = dwSourceIndex; lpsice->dwSourceIndex = dwSourceIndex;
index = pDPA_InsertPtr(hdpa, 0x7fff, lpsice); index = pDPA_InsertPtr(sic_hdpa, 0x7fff, lpsice);
if ( INVALID_INDEX == index ) if ( INVALID_INDEX == index )
{ SHFree(lpsice); { SHFree(lpsice);
return INVALID_INDEX; return INVALID_INDEX;
@ -551,8 +548,8 @@ INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
sice.sSourceFile = PathFindFilenameA(sSourceFile); sice.sSourceFile = PathFindFilenameA(sSourceFile);
sice.dwSourceIndex = dwSourceIndex; sice.dwSourceIndex = dwSourceIndex;
if (NULL != pDPA_GetPtr (hdpa, 0)) if (NULL != pDPA_GetPtr (sic_hdpa, 0))
{ index = pDPA_Search (hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0); { index = pDPA_Search (sic_hdpa, &sice, -1L, SIC_CompareEntrys, 0, 0);
} }
if ( INVALID_INDEX == index ) if ( INVALID_INDEX == index )
@ -560,7 +557,7 @@ INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
} }
TRACE("-- found\n"); TRACE("-- found\n");
return ((LPSIC_ENTRY)pDPA_GetPtr(hdpa, index))->dwListIndex; return ((LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, index))->dwListIndex;
} }
/**************************************************************************** /****************************************************************************
* SIC_LoadIcon [internal] * SIC_LoadIcon [internal]
@ -598,12 +595,12 @@ BOOL SIC_Initialize(void)
TRACE("\n"); TRACE("\n");
if (hdpa) /* already initialized?*/ if (sic_hdpa) /* already initialized?*/
return TRUE; return TRUE;
hdpa = pDPA_Create(16); sic_hdpa = pDPA_Create(16);
if (!hdpa) if (!sic_hdpa)
{ return(FALSE); { return(FALSE);
} }
@ -652,13 +649,19 @@ void SIC_Destroy(void)
LPSIC_ENTRY lpsice; LPSIC_ENTRY lpsice;
int i; int i;
if (hdpa && NULL != pDPA_GetPtr (hdpa, 0)) TRACE("\n");
{ for (i=0; i < pDPA_GetPtrCount(hdpa); ++i)
{ lpsice = pDPA_GetPtr(hdpa, i); 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); SHFree(lpsice);
} }
pDPA_Destroy(hdpa); pDPA_Destroy(sic_hdpa);
} }
sic_hdpa = NULL;
} }
/************************************************************************* /*************************************************************************
* Shell_GetImageList [SHELL32.71] * Shell_GetImageList [SHELL32.71]

View File

@ -416,7 +416,7 @@ DWORD WINAPI SHGetDesktopFolder(LPSHELLFOLDER *shellfolder)
{ hres = NOERROR; { hres = NOERROR;
} }
else else
{ lpclf = IClassFactory_Constructor(); { lpclf = IClassFactory_Constructor(&CLSID_ShellDesktop);
if(lpclf) if(lpclf)
{ hres = IClassFactory_CreateInstance(lpclf,NULL,(REFIID)&IID_IShellFolder, (void*)&pdesktopfolder); { hres = IClassFactory_CreateInstance(lpclf,NULL,(REFIID)&IID_IShellFolder, (void*)&pdesktopfolder);
IClassFactory_Release(lpclf); IClassFactory_Release(lpclf);
@ -1058,6 +1058,7 @@ HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
} }
/************************************************************************* /*************************************************************************
* global variables of the shell32.dll * global variables of the shell32.dll
* all are once per process
* *
*/ */
void (WINAPI* pDLLInitComctl)(LPVOID); void (WINAPI* pDLLInitComctl)(LPVOID);
@ -1089,6 +1090,11 @@ static INT shell32_RefCount = 0;
INT shell32_ObjCount = 0; INT shell32_ObjCount = 0;
HINSTANCE shell32_hInstance; HINSTANCE shell32_hInstance;
HIMAGELIST ShellSmallIconList = 0;
HIMAGELIST ShellBigIconList = 0;
HDPA sic_hdpa = 0;
/************************************************************************* /*************************************************************************
* SHELL32 LibMain * SHELL32 LibMain
* *
@ -1102,12 +1108,16 @@ BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
shell32_hInstance = hinstDLL; shell32_hInstance = hinstDLL;
switch (fdwReason) switch (fdwReason)
{ case DLL_PROCESS_ATTACH: {
case DLL_PROCESS_ATTACH:
if (!bShell32IsInitialized) if (!bShell32IsInitialized)
{ hComctl32 = LoadLibraryA("COMCTL32.DLL"); {
hComctl32 = LoadLibraryA("COMCTL32.DLL");
hUser32 = GetModuleHandleA("USER32"); hUser32 = GetModuleHandleA("USER32");
if (hComctl32 && hUser32) if (hComctl32 && hUser32)
{ pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx"); {
pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
if (pDLLInitComctl) if (pDLLInitComctl)
{ pDLLInitComctl(NULL); { pDLLInitComctl(NULL);
} }
@ -1158,10 +1168,11 @@ BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
if (pdesktopfolder) if (pdesktopfolder)
{ IShellFolder_Release(pdesktopfolder); { IShellFolder_Release(pdesktopfolder);
pdesktopfolder = NULL;
} }
SIC_Destroy(); SIC_Destroy();
FreeLibrary(hComctl32); FreeLibrary(hComctl32);
/* this one is here to check if AddRef/Release is balanced */ /* this one is here to check if AddRef/Release is balanced */
if (shell32_ObjCount) if (shell32_ObjCount)

View File

@ -22,8 +22,9 @@
*/ */
extern HINSTANCE shell32_hInstance; extern HINSTANCE shell32_hInstance;
extern INT shell32_ObjCount; extern INT shell32_ObjCount;
extern HIMAGELIST ShellSmallIconList; extern HIMAGELIST ShellSmallIconList;
extern HIMAGELIST ShellBigIconList; extern HIMAGELIST ShellBigIconList;
extern HDPA sic_hdpa;
/******************************************* /*******************************************
* pointer to functions dynamically loaded * 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 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPSHELLFOLDER psf, LPITEMIDLIST * apidl, UINT cidl);
extern LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT, const FORMATETC []); extern LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT, const FORMATETC []);
extern LPCLASSFACTORY IShellLink_CF_Constructor(void); extern LPCLASSFACTORY IClassFactory_Constructor(REFCLSID);
extern LPCLASSFACTORY IShellLinkW_CF_Constructor(void);
extern LPCLASSFACTORY IClassFactory_Constructor(void);
extern LPCONTEXTMENU IContextMenu_Constructor(LPSHELLFOLDER, LPCITEMIDLIST *, UINT); extern LPCONTEXTMENU IContextMenu_Constructor(LPSHELLFOLDER, LPCITEMIDLIST *, UINT);
extern LPSHELLVIEW IShellView_Constructor(LPSHELLFOLDER, LPCITEMIDLIST); extern LPSHELLVIEW IShellView_Constructor(LPSHELLFOLDER, LPCITEMIDLIST);
extern LPSHELLLINK IShellLink_Constructor(void); extern LPSHELLLINK IShellLink_Constructor(BOOL);
extern LPSHELLLINKW IShellLinkW_Constructor(void);
extern LPENUMIDLIST IEnumIDList_Constructor(LPCSTR,DWORD); extern LPENUMIDLIST IEnumIDList_Constructor(LPCSTR,DWORD);
extern LPEXTRACTICONA IExtractIconA_Constructor(LPITEMIDLIST); 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 */ /* fixme: rename the functions when the shell32.dll has it's own exports namespace */
HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv); HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);