Bug 1430312: Use StaticRefPtr instead of raw pointer for nsImageFrame::gIconLoad. r=tnikkel
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 12 Jan 2018 16:49:48 -0800
changeset 451013 0a4e3d4de37415d0fec3f5bfb644ffa3da7eb659
parent 451012 cbb0db087e5e5960ee25391873cde70998efbf88
child 451014 5c8565f103fe81130f9b528e278461efb6c8de7f
child 451020 93340ac5ecd8d2791176d3e9656f6d1aff3f3092
push id8543
push userryanvm@gmail.com
push dateTue, 16 Jan 2018 14:33:22 +0000
treeherdermozilla-beta@a6525ed16a32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1430312: Use StaticRefPtr instead of raw pointer for nsImageFrame::gIconLoad. r=tnikkel MozReview-Commit-ID: HvkQEaZS1OG
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -97,17 +97,17 @@ using namespace mozilla::layers;
 //we must add hooks soon
 // Default alignment value (so we can tell an unset value from a set value)
 #define ALIGN_UNSET uint8_t(-1)
 // static icon information
-nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nullptr;
+StaticRefPtr<nsImageFrame::IconLoad> nsImageFrame::gIconLoad;
 // cached IO service for loading icons
 nsIIOService* nsImageFrame::sIOService;
 // test if the width and height are fixed, looking at the style data
 // This is used by nsImageFrame::ShouldCreateImageFrameFor and should
 // not be used for layout decisions.
 static bool HaveSpecifiedSize(const nsStylePosition* aStylePosition)
@@ -2353,17 +2353,16 @@ nsImageFrame::GetLoadGroup(nsPresContext
 nsresult nsImageFrame::LoadIcons(nsPresContext *aPresContext)
   NS_ASSERTION(!gIconLoad, "called LoadIcons twice");
   gIconLoad = new IconLoad();
-  NS_ADDREF(gIconLoad);
   nsresult rv;
   // create a loader and load the images
   rv = LoadIcon(loadingSrc,
   if (NS_FAILED(rv)) {
     return rv;
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -14,16 +14,17 @@
 #include "nsIObserver.h"
 #include "imgINotificationObserver.h"
 #include "nsDisplayList.h"
 #include "imgIContainer.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/DebugOnly.h"
+#include "mozilla/StaticPtr.h"
 #include "nsIReflowCallback.h"
 #include "nsTObserverArray.h"
 class nsFontMetrics;
 class nsImageMap;
 class nsIURI;
 class nsILoadGroup;
 class nsDisplayImage;
@@ -127,17 +128,17 @@ public:
   virtual LogicalSides GetLogicalSkipSides(const ReflowInput* aReflowInput = nullptr) const override;
   nsresult GetIntrinsicImageSize(nsSize& aSize);
   static void ReleaseGlobals() {
     if (gIconLoad) {
-      NS_RELEASE(gIconLoad);
+      gIconLoad = nullptr;
   nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData);
    * Function to test whether aContent, which has aStyleContext as its style,
@@ -390,17 +391,18 @@ private:
     RefPtr<imgRequestProxy> mLoadingImage;
     RefPtr<imgRequestProxy> mBrokenImage;
     bool             mPrefForceInlineAltText;
     bool             mPrefShowPlaceholders;
     bool             mPrefShowLoadingPlaceholder;
-  static IconLoad* gIconLoad; // singleton pattern: one LoadIcons instance is used
+  // singleton pattern: one LoadIcons instance is used
+  static mozilla::StaticRefPtr<IconLoad> gIconLoad;
   friend class nsDisplayImage;
  * Note that nsDisplayImage does not receive events. However, an image element
  * is replaced content so its background will be z-adjacent to the
  * image itself, and hence receive events just as if the image itself