Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Bug 658995 part 2 - Use static destructors instead of atexit(). r=bsm…
Browse files Browse the repository at this point in the history
…edberg
  • Loading branch information
glandium committed Jun 15, 2011
1 parent 4d9953b commit feaaf33
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
15 changes: 12 additions & 3 deletions netwerk/base/src/nsStandardURL.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion profile/dirserviceprovider/src/nsProfileLock.cpp
Expand Up @@ -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.,
Expand Down
14 changes: 6 additions & 8 deletions profile/dirserviceprovider/src/nsProfileLock.h
Expand Up @@ -99,14 +99,12 @@ class nsProfileLock
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
Expand Down
2 changes: 1 addition & 1 deletion tools/trace-malloc/lib/nsTraceMalloc.c
Expand Up @@ -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 */
Expand Down
16 changes: 16 additions & 0 deletions tools/trace-malloc/lib/nsTypeInfo.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit feaaf33

Please sign in to comment.