From aeb8d098535a9f296612d7b6193051987230fa30 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Tue, 20 Feb 2001 13:50:26 +0000 Subject: [PATCH] Improve the boehm GC's ability to dump all leaked objects at shutdown. Patch partly by waterson@netscape.com, partly by me. r=beard@netscape.com sr=brendan@mozilla.org b=59967 git-svn-id: svn://10.0.0.236/trunk@87448 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gc/boehm/mark_rts.c | 3 ++- mozilla/xpcom/base/nsLeakDetector.cpp | 32 ++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/mozilla/gc/boehm/mark_rts.c b/mozilla/gc/boehm/mark_rts.c index 6ec43b33cc9..193c741bfa2 100644 --- a/mozilla/gc/boehm/mark_rts.c +++ b/mozilla/gc/boehm/mark_rts.c @@ -495,7 +495,8 @@ ptr_t cold_gc_frame; # if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(PCR)) \ && !defined(SRC_M3) GC_remove_tmp_roots(); - GC_register_dynamic_libraries(); + if (GC_root_size) + GC_register_dynamic_libraries(); # endif /* Mark everything in static data areas */ for (i = 0; i < n_root_sets; i++) { diff --git a/mozilla/xpcom/base/nsLeakDetector.cpp b/mozilla/xpcom/base/nsLeakDetector.cpp index d3266d827e9..62edb96da5c 100644 --- a/mozilla/xpcom/base/nsLeakDetector.cpp +++ b/mozilla/xpcom/base/nsLeakDetector.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -183,7 +183,22 @@ nsresult NS_InitLeakDetector() return rv; } -nsresult NS_ShutdownLeakDetector() +#undef SHUTDOWN_LEAKS_EARLY +#undef SHUTDOWN_LEAKS_MEDIUM +#define SHUTDOWN_LEAKS_LATE + +class LeakDetectorFinalizer +{ +public: + ~LeakDetectorFinalizer(); +}; + +#ifdef SHUTDOWN_LEAKS_LATE +// do shutdown leaks when XPCOM library is unloaded +LeakDetectorFinalizer gLeakDetectorFinalizer; +#endif + +LeakDetectorFinalizer::~LeakDetectorFinalizer() { GC_gcollect(); @@ -195,8 +210,19 @@ nsresult NS_ShutdownLeakDetector() GC_gcollect(); } #endif +} - return NS_OK; +nsresult NS_ShutdownLeakDetector() +{ +#if defined(SHUTDOWN_LEAKS_MEDIUM) + // Make this the first atexit() called so it's before the atexit() crashes + // see http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=23552 + static LeakDetectorFinalizer trick; +#elsif defined(SHUTDOWN_LEAKS_EARLY) + // do shutdown leaks now + LeakDetectorFinalizer trick; +#endif + return NS_OK; } #endif /* defined(GC_LEAK_DETECTOR) */