bug 1316165 ensure xcb_get_input_focus_reply is called to avoid leaking the reply r=lsalzman
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 09 Nov 2016 08:56:27 +1300
changeset 321845 2635cff0413bd1d4c6b0be57b579aa41393ad1ab
parent 321844 2ab7ed6880d3e0f973d1209ba4f1639f6f89d00f
child 321846 d78a1d9f6a4a82a3f134c095ead3d6ecf95ec204
push id30936
push usercbook@mozilla.com
push dateThu, 10 Nov 2016 15:58:19 +0000
treeherdermozilla-central@4ee98684375e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1316165
milestone52.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 1316165 ensure xcb_get_input_focus_reply is called to avoid leaking the reply r=lsalzman MozReview-Commit-ID: JPi0TeKVCB5
widget/nsShmImage.cpp
widget/nsShmImage.h
--- a/widget/nsShmImage.cpp
+++ b/widget/nsShmImage.cpp
@@ -233,31 +233,39 @@ nsShmImage::DestroyImage()
     xcb_free_pixmap(mConnection, mPixmap);
     mPixmap = XCB_NONE;
   }
   if (mShmSeg != XCB_NONE) {
     xcb_shm_detach_checked(mConnection, mShmSeg);
     mShmSeg = XCB_NONE;
   }
   DestroyShmSegment();
+  // Avoid leaking any pending reply.  No real need to wait but CentOS 6 build
+  // machines don't have xcb_discard_reply().
+  WaitIfPendingReply();
+}
+
+// Wait for any in-flight shm-affected requests to complete.
+// Typically X clients would wait for a XShmCompletionEvent to be received,
+// but this works as it's sent immediately after the request is sent.
+void
+nsShmImage::WaitIfPendingReply()
+{
+  if (mRequestPending) {
+    xcb_get_input_focus_reply_t* reply =
+      xcb_get_input_focus_reply(mConnection, mSyncRequest, nullptr);
+    free(reply);
+    mRequestPending = false;
+  }
 }
 
 already_AddRefed<DrawTarget>
 nsShmImage::CreateDrawTarget(const mozilla::LayoutDeviceIntRegion& aRegion)
 {
-  // Wait for any in-flight requests to complete.
-  // Typically X clients would wait for a XShmCompletionEvent to be received,
-  // but this works as it's sent immediately after the request is processed.
-  if (mRequestPending) {
-    xcb_get_input_focus_reply_t* reply;
-    if ((reply = xcb_get_input_focus_reply(mConnection, mSyncRequest, nullptr))) {
-      free(reply);
-    }
-    mRequestPending = false;
-  }
+  WaitIfPendingReply();
 
   // Due to bug 1205045, we must avoid making GTK calls off the main thread to query window size.
   // Instead we just track the largest offset within the image we are drawing to and grow the image
   // to accomodate it. Since usually the entire window is invalidated on the first paint to it,
   // this should grow the image to the necessary size quickly without many intermediate reallocations.
   IntRect bounds = aRegion.GetBounds().ToUnknownRect();
   IntSize size(bounds.XMost(), bounds.YMost());
   if (size.width > mSize.width || size.height > mSize.height) {
--- a/widget/nsShmImage.h
+++ b/widget/nsShmImage.h
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __mozilla_widget_nsShmImage_h__
 #define __mozilla_widget_nsShmImage_h__
 
@@ -43,16 +43,18 @@ private:
   bool InitExtension();
 
   bool CreateShmSegment();
   void DestroyShmSegment();
 
   bool CreateImage(const mozilla::gfx::IntSize& aSize);
   void DestroyImage();
 
+  void WaitIfPendingReply();
+
   xcb_connection_t*            mConnection;
   Window                       mWindow;
   Visual*                      mVisual;
   unsigned int                 mDepth;
 
   mozilla::gfx::SurfaceFormat  mFormat;
   mozilla::gfx::IntSize        mSize;