From e4c2edd119758f79b49e5897e4eca202933ae35c Mon Sep 17 00:00:00 2001 From: "av%netscape.com" Date: Sun, 31 Mar 2002 05:59:15 +0000 Subject: [PATCH] Fixing crash in Tester plugin after it chooses not to unload -- not part of the build --- modules/plugin/tools/tester/common/logger.cpp | 13 ++++++++++++- modules/plugin/tools/tester/common/np_entry.cpp | 2 +- modules/plugin/tools/tester/common/npp_gate.cpp | 14 ++++++++++++++ modules/plugin/tools/tester/common/plugbase.cpp | 2 +- modules/plugin/tools/tester/include/logger.h | 5 +++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/modules/plugin/tools/tester/common/logger.cpp b/modules/plugin/tools/tester/common/logger.cpp index 3a0a6a761a8f..00f13c72ec46 100644 --- a/modules/plugin/tools/tester/common/logger.cpp +++ b/modules/plugin/tools/tester/common/logger.cpp @@ -59,7 +59,8 @@ CLogger::CLogger(LPSTR szTarget) : m_bBlockLogToFrame(FALSE), m_pStream(NULL), m_dwStartTime(0xFFFFFFFF), - m_iStringDataWrap(LOGGER_DEFAULT_STRING_WRAP) + m_iStringDataWrap(LOGGER_DEFAULT_STRING_WRAP), + m_bStale(FALSE) { if(szTarget != NULL) strcpy(m_szTarget, szTarget); @@ -329,3 +330,13 @@ void CLogger::blockDumpToFrame(BOOL bBlock) { m_bBlockLogToFrame = bBlock; } + +void CLogger::markStale() +{ + m_bStale = TRUE; +} + +BOOL CLogger::isStale() +{ + return m_bStale; +} diff --git a/modules/plugin/tools/tester/common/np_entry.cpp b/modules/plugin/tools/tester/common/np_entry.cpp index fe65e5c90a72..fba93eb40b97 100644 --- a/modules/plugin/tools/tester/common/np_entry.cpp +++ b/modules/plugin/tools/tester/common/np_entry.cpp @@ -45,7 +45,7 @@ #include "logger.h" CLogger * pLogger = NULL; -static char szTarget[] = "_npapi_Log"; +static char szTarget[] = LOGGER_DEFAULT_TARGET; NPNetscapeFuncs NPNFuncs; diff --git a/modules/plugin/tools/tester/common/npp_gate.cpp b/modules/plugin/tools/tester/common/npp_gate.cpp index d9286f0bc6bd..388c9422aaa6 100644 --- a/modules/plugin/tools/tester/common/npp_gate.cpp +++ b/modules/plugin/tools/tester/common/npp_gate.cpp @@ -44,6 +44,7 @@ extern CLogger * pLogger; static char szINIFile[] = NPAPI_INI_FILE_NAME; +static char szTarget[] = LOGGER_DEFAULT_TARGET; // here the plugin creates a plugin instance object which // will be associated with this newly created NPP instance and @@ -67,6 +68,15 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, ch } instance->pdata = (void *)pPlugin; + + // recreate logger if needed + if (!pLogger) + pLogger = new CLogger(szTarget); + else if (pLogger->isStale()) { + delete pLogger; + pLogger = new CLogger(szTarget); + } + pLogger->associate(pPlugin); char szFileName[_MAX_PATH]; @@ -106,6 +116,10 @@ Return: DWORD dwTickReturn = XP_GetTickCount(); pLogger->appendToLog(action_npp_destroy, dwTickEnter, dwTickReturn, (DWORD)ret, (DWORD)instance, (DWORD)save); pLogger->blockDumpToFrame(FALSE); + + // mark logger stale as the dll can remain in memory with no NP_Shutdown called + // and then come back with NPP_New where we should recreate the logger + pLogger->markStale(); return ret; } diff --git a/modules/plugin/tools/tester/common/plugbase.cpp b/modules/plugin/tools/tester/common/plugbase.cpp index 456a9251629f..5b1b21854284 100644 --- a/modules/plugin/tools/tester/common/plugbase.cpp +++ b/modules/plugin/tools/tester/common/plugbase.cpp @@ -44,7 +44,7 @@ extern CLogger * pLogger; static char szINIFile[] = NPAPI_INI_FILE_NAME; #ifdef XP_UNIX - static char szTarget[] = "_npapi_Log"; + static char szTarget[] = LOGGER_DEFAULT_TARGET; #endif CPluginBase::CPluginBase(NPP pNPInstance, WORD wMode) : diff --git a/modules/plugin/tools/tester/include/logger.h b/modules/plugin/tools/tester/include/logger.h index 84e4ab061e19..af03df33ba0d 100644 --- a/modules/plugin/tools/tester/include/logger.h +++ b/modules/plugin/tools/tester/include/logger.h @@ -61,6 +61,7 @@ private: DWORD m_dwStartTime; char m_szItemSeparator[80]; int m_iStringDataWrap; + BOOL m_bStale; public: CLogger(LPSTR szTarget = NULL); @@ -92,9 +93,13 @@ public: void blockDumpToFrame(BOOL bBlock); void closeLogToFile(); + + void markStale(); + BOOL isStale(); }; #define LOGGER_DEFAULT_STRING_WRAP 32 +#define LOGGER_DEFAULT_TARGET "_npapi_Log" // Preferences profile stuff #define SECTION_LOG "Log"