Bug 1425878 - Don't expose raw pointers to refcounted vsync dispatcher object. r?sotaro draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 18 Dec 2017 13:33:56 -0500
changeset 712773 daa41aa8219554479a8ace2ec2194fd3b87f514d
parent 712645 5572465c08a9ce0671dcd01c721f9356fcd53a65
child 744138 7be717e8910376140fb1ce5c2e6d61977f919dc5
push id93426
push userkgupta@mozilla.com
push dateMon, 18 Dec 2017 19:08:43 +0000
reviewerssotaro
bugs1425878
milestone59.0a1
Bug 1425878 - Don't expose raw pointers to refcounted vsync dispatcher object. r?sotaro MozReview-Commit-ID: 5ywkZqfY8uZ
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -1250,20 +1250,21 @@ void nsBaseWidget::CreateCompositorVsync
   // Parent directly listens to the vsync source whereas
   // child process communicate via IPC
   // Should be called AFTER gfxPlatform is initialized
   if (XRE_IsParentProcess()) {
     mCompositorVsyncDispatcher = new CompositorVsyncDispatcher();
   }
 }
 
-CompositorVsyncDispatcher*
+already_AddRefed<CompositorVsyncDispatcher>
 nsBaseWidget::GetCompositorVsyncDispatcher()
 {
-  return mCompositorVsyncDispatcher;
+  RefPtr<CompositorVsyncDispatcher> dispatcher = mCompositorVsyncDispatcher;
+  return dispatcher.forget();
 }
 
 already_AddRefed<LayerManager>
 nsBaseWidget::CreateCompositorSession(int aWidth,
                                       int aHeight,
                                       CompositorOptions* aOptionsOut)
 {
   MOZ_ASSERT(aOptionsOut);
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -204,17 +204,17 @@ public:
   // A remote compositor session tied to this window has been lost and IPC
   // messages will no longer work. The widget must clean up any lingering
   // resources and possibly schedule another paint.
   //
   // A reference to the session object is held until this function has
   // returned.
   void NotifyCompositorSessionLost(mozilla::layers::CompositorSession* aSession);
 
-  mozilla::CompositorVsyncDispatcher* GetCompositorVsyncDispatcher();
+  already_AddRefed<mozilla::CompositorVsyncDispatcher> GetCompositorVsyncDispatcher();
   void            CreateCompositorVsyncDispatcher();
   virtual void            CreateCompositor();
   virtual void            CreateCompositor(int aWidth, int aHeight);
   virtual void            SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) {}
   virtual void            PrepareWindowEffects() override {}
   virtual void            UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
   virtual void            SetModal(bool aModal) override {}
   virtual uint32_t        GetMaxTouchPoints() const override;