Closed Bug 107485 Opened 23 years ago Closed 19 years ago

nsPluginHostImpl's shutdown listener should be a weak reference

Categories

(Core Graveyard :: Plug-ins, defect)

x86
All
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: depman1, Assigned: timeless)

References

Details

Attachments

(1 obsolete file)

reproduced with 10/27 debug mozilla nightly build.
1. Set up debugger in VC++ & set breakpoint in nsComponentManager.cpp: line 2075
2. Launch app in the debugger (F5).
3. Quit the app.
4. Check the stack trace and doubleclick on destructor line:
nsPluginHostImpl::~nsPluginHostImpl() line 2430
Result: Destructor in nsPluginHostImpl() calls do_GetService
Expected: Should register shutdown listener. 

Here's the code for the destructor. It's using nsIObserverService object:
nsPluginHostImpl::~nsPluginHostImpl()
{
  PLUGIN_LOG(PLUGIN_LOG_ALWAYS,("nsPluginHostImpl::dtor\n"));

#ifdef NS_DEBUG
  printf("nsPluginHostImpl dtor\n");
#endif
  nsCOMPtr<nsIObserverService> obsService =
do_GetService("@mozilla.org/observer-service;1");
  if (obsService)
  {
    obsService->RemoveObserver(this, "quit-application");
    obsService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
  }
  Destroy();
}
Blocks: 107391
We are already using a shutdown listener here! In fact, the code in the
destructor is unregistering the listener and thefore needs to
do_GetService(nsIObserverService). Would it help to move this unregistering code
to nsPluginHostImpl::Destroy()? This can only be called once....whoever is
first, either the shutdown observer or ~nsPluginHostImpl. Please advise.

I recall one of the reason this being done was there once a bug (and could still
be) that ~nsPluginHostImpl would not always be called at browser shutdown and
plugins wouldn't be able to clean themselves up (bad!). I think one of the
reason it wasn't called was because the service manager was being held past
XPCOM shutdown. Well, it just so happens, that at least on Windows, the JRE
1.3.x Java plugin would hold on to the service manager and cause this bug! I'm
not sure if this is accurate, but I was told the reason Java did this was for
the Java console or taskbar icon or something.
You should impl nsWeakReference, and then use PR_TRUE as the last argument to
AddObserver. That way you won't need to unregister yourself.
Attached patch patch (obsolete) — Splinter Review
did I get it right?
Keywords: patch
OS: Windows NT → All
removing myself from cc:
bug 100212 comment 38 fixed the core problem.
Assignee: av → timeless
Comment on attachment 71484 [details] [diff] [review]
patch

yup, you got it right. r=dougt.
Attachment #71484 - Flags: review+
Status: NEW → ASSIGNED
Summary: nsPluginHostImpl calls getService on shutdown; should register shutdown listener → nsPluginHostImpl's shutdown listener should be a weak reference
Comment on attachment 71484 [details] [diff] [review]
patch

sr=darin
Attachment #71484 - Flags: superreview+
wasn't this supposed to be checked in?
Comment on attachment 71484 [details] [diff] [review]
patch

2002-05-30:
mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp	1.390
mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp	1.389
mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp	1.388
mozilla/modules/plugin/base/src/nsPluginHostImpl.h	1.77
Attachment #71484 - Attachment is obsolete: true
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: