Bug 658995 part 2 - Use static destructors instead of atexit(). r=bsmedberg

This commit is contained in:
Mike Hommey 2011-06-15 07:32:03 +02:00
parent 085cc21666
commit 899e31b0e1
5 changed files with 39 additions and 13 deletions

View File

@ -325,7 +325,12 @@ nsStandardURL::~nsStandardURL()
}
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
static void DumpLeakedURLs()
struct DumpLeakedURLs {
DumpLeakedURLs() {}
~DumpLeakedURLs();
};
DumpLeakedURLs::~DumpLeakedURLs()
{
if (!PR_CLIST_IS_EMPTY(&gAllURLs)) {
printf("Leaked URLs:\n");
@ -363,8 +368,12 @@ nsStandardURL::ShutdownGlobalObjects()
NS_IF_RELEASE(gCharsetMgr);
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
if (gInitialized)
atexit(DumpLeakedURLs);
if (gInitialized) {
// This instanciates a dummy class, and will trigger the class
// destructor when libxul is unloaded. This is equivalent to atexit(),
// but gracefully handles dlclose().
static DumpLeakedURLs d;
}
#endif
}

View File

@ -390,7 +390,10 @@ nsresult nsProfileLock::LockWithSymlink(const nsACString& lockFilePath, PRBool a
if (!setupPidLockCleanup++)
{
// Clean up on normal termination.
atexit(RemovePidLockFilesExiting);
// This instanciates a dummy class, and will trigger the class
// destructor when libxul is unloaded. This is equivalent to atexit(),
// but gracefully handles dlclose().
static RemovePidLockFilesExiting r;
// Clean up on abnormal termination, using POSIX sigaction.
// Don't arm a handler if the signal is being ignored, e.g.,

View File

@ -99,14 +99,12 @@ private:
LHANDLE mLockFileHandle;
#elif defined (XP_UNIX)
static void RemovePidLockFilesExiting()
{
// We can't implement this function with a default parameter on
// RemovePidLockFiles(aFatalSignal) since we register
// atexit(RemovePidLockFilesExiting).
RemovePidLockFiles(PR_FALSE);
}
struct RemovePidLockFilesExiting {
RemovePidLockFilesExiting() {}
~RemovePidLockFilesExiting() {
RemovePidLockFiles(PR_FALSE);
}
};
static void RemovePidLockFiles(PRBool aFatalSignal);
static void FatalSignalHandler(int signo

View File

@ -1365,7 +1365,7 @@ NS_TraceMallocStartup(int logfd)
log_header(logfd);
}
atexit(NS_TraceMallocShutdown);
RegisterTraceMallocShutdown();
tmlock = PR_NewLock();
(void) tm_get_thread(); /* ensure index initialization while it's easy */

View File

@ -54,6 +54,22 @@
extern "C" const char* nsGetTypeName(void* ptr);
extern "C" void NS_TraceMallocShutdown();
struct TraceMallocShutdown {
TraceMallocShutdown() {}
~TraceMallocShutdown() {
NS_TraceMallocShutdown();
}
};
extern "C" void RegisterTraceMallocShutdown() {
// This instanciates the dummy class above, and will trigger the class
// destructor when libxul is unloaded. This is equivalent to atexit(),
// but gracefully handles dlclose().
static TraceMallocShutdown t;
}
class IUnknown {
public:
virtual long QueryInterface() = 0;