Bug 1210912 - fix widget leak in LookupRegisteredPluginWindow; r=roc
authorNathan Froyd <froydnj@mozilla.com>
Fri, 02 Oct 2015 22:00:56 -0400
changeset 299529 e54d330a1de68a83e3ccf65c75f0fc970f7d872c
parent 299528 21a11ea9774895d651943e27e94e487ad027a089
child 299530 8966326bc731912b5e86d5e07eb00e4ed9baf86c
push id5392
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:08:23 +0000
treeherdermozilla-beta@16ce8562a975 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1210912
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1210912 - fix widget leak in LookupRegisteredPluginWindow; r=roc nsRefPtrHashtable::Get follows XPCOM outparam rules, so it addrefs its argument prior to returning it. LookupRegisteredPluginWindow, however, doesn't know anything about the additional reference, and neither does anything else that calls it (which is, fortunately, not that much code). So every widget returned by this function will leak. To fix this, we use nsRefPtrHashtable::GetWeak, which doesn't addref its argument, but merely returns the raw pointer, leaving the hashtable responsible for the owning reference.
widget/nsBaseWidget.cpp
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -1845,20 +1845,18 @@ nsBaseWidget::UnregisterPluginWindowForR
 nsIWidget*
 nsIWidget::LookupRegisteredPluginWindow(uintptr_t aWindowID)
 {
 #if !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
   NS_NOTREACHED("nsBaseWidget::LookupRegisteredPluginWindow not implemented!");
   return nullptr;
 #else
   MOZ_ASSERT(NS_IsMainThread());
-  nsIWidget* widget = nullptr;
   MOZ_ASSERT(sPluginWidgetList);
-  sPluginWidgetList->Get((void*)aWindowID, &widget);
-  return widget;
+  return sPluginWidgetList->GetWeak((void*)aWindowID);
 #endif
 }
 
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
 struct VisEnumContext {
   uintptr_t parentWidget;
   const nsTArray<uintptr_t>* list;
   bool widgetVisibilityFlag;