Closed Bug 45068 Opened 25 years ago Closed 14 years ago

NS_ShutdownXPCOM followed by NS_InitXPCOM leaks and crashes

Categories

(Core :: XPCOM, enhancement, P4)

enhancement

Tracking

()

RESOLVED WONTFIX
Future

People

(Reporter: jonsmirl, Unassigned)

References

Details

(4 keywords)

From Bugzilla Helper: User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95) BuildID: CVS NS_ShutdownXPCOM followed by NS_InitXPCOM. Right now I can shutdown ok but when I reinit XPCOM I GPF on NS_ADDREF(thread) in GetIThread(). It looks like self- >privateData in PR_GetThreadPrivate is pointing to memory that was freed in XPCOM shutdown. Reproducible: Always Steps to Reproduce: NS_ShutdownXPCOM followed by NS_InitXPCOM
Here's the fix, a dangling point is left in the thread local storage after the thread object has been deleted. Change the shutdown function in xpcom/threads/nsThread.cpp... void nsThread::Shutdown() { if (gMainThread) { // XXX nspr doesn't seem to be calling the main thread's destructor // callback, so let's help it out: nsThread::Exit(NS_STATIC_CAST(nsThread*, gMainThread)); // this will cause gMainThread to be released PR_SetThreadPrivate (nsThread::kIThreadSelfIndex, NULL); // don't keep a dangling reference gMainThread = NULL; // nsrefcnt cnt; // NS_RELEASE2(gMainThread, cnt); // NS_WARN_IF_FALSE(cnt == 0, "Main thread being held past XPCOM shutdown."); } } fix the destructor in xpcom/ds/nsDirectoryService.cpp... nsDirectoryService::~nsDirectoryService() { leave everything as is, add: mService = NULL; }
setting bug status to New and adding patch keyword
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: patch
Status: NEW → ASSIGNED
Target Milestone: --- → M20
Adding a dependency between this bug and 38671.
Depends on: 38671
Added embed keyword
Keywords: embed
Added some people to the CC for this bug
Can we, for now, just eliminate the actual shutdown and second startup code except in debug environments or environments where people are looking for leaks?
ray, this is an embedded use of xpcom. So that we do not leak all over the place, we need to allow for a shutdown - startup. Lets address the problems and not bandaide the problem.
OK. My answer is to remove the function NS_ShutdownXPCOM, and have a single function that can be called anywhere to track outstanding leaks. Actual shutdown of XPCOM will not happen soon. I will fix this in M18 if you agree with this solution. Otherwise, it becomes future.
This is not acceptable for componentization because object based on XPCOM will leak a huge chunk of memory into their host's address space with no way of cleaning it up. Basically, as far as the host process is concerned, it creates some component (GTK, ActiveX, whatever) and when it decides to delete it, all the memory that the component used should go too. If we delete NS_TermXPCOM then that's obviously impossible. If you're concerned about services and marshalled pointers still being alive and refcounted when NS_TermXPCOM is called, then we need to establish some rules of behaviour for these objects. Perhaps services should be singletons for instance that ignore calls to AddRef and *always* go away when the Term happens? Anyone who tries to call them after is in error and a crash is their just desserts. Or maybe services/marshalled pointers should return NS_ERROR_XPCOM_NOT_INITIALISED if they are called when XPCOM is not initialised?
Perhaps we could schedule meetings this week, starting today, identifying the real requirements you are trying to solve and all the XPCOM changes that are required for this enhancement.
Target Milestone: M20 → Future
Assigning rest of xpcom stuff to myself (from Ray).
Assignee: rayw → warren
Status: ASSIGNED → NEW
Target Milestone: Future → mozilla1.0
QA Contact: leger → kandrot
reasigning warren bugs to default component owners.
Assignee: warren → kandrot
QA Contact: kandrot → scc
Target Milestone: mozilla1.0 → ---
reassign all kandrot xpcom bug.
Assignee: kandrot → dougt
Blocks: 98283
Target Milestone: --- → mozilla1.1
moving out based on my workload. Yell, if you have a problem.
Keywords: helpwanted
Target Milestone: mozilla1.1alpha → Future
Keywords: topembed+
Summary: NS_ShutdownXPCOM followed by NS_InitXPCOM → NS_ShutdownXPCOM followed by NS_InitXPCOM leaks and crashes
per discussion w/ dougt, topembed minusing this bug.
Keywords: topembed+topembed-
Keywords: crash
Assignee: dougt → nobody
QA Contact: scc → xpcom
Assignee: nobody → benjamin
Severity: normal → enhancement
OS: Windows 95 → All
Hardware: PC → All
Target Milestone: Future → mozilla1.9alpha
Assignee: benjamin → nobody
Priority: P3 → P4
Target Milestone: mozilla1.9alpha1 → Future
bsmedberg, can you tell whether this bug is (still) valid?
Yes, I'd like this to remain open.
I'm now going to reverse my 2009-self and close this, it's not something we are actually doing or planning on doing.
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.