bug 1316165 ensure xcb_get_input_focus_reply is called to avoid leaking the reply r?lsalzman draft
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 09 Nov 2016 08:56:27 +1300
changeset 435660 1ad8655d936bcb4219967f84dd958458d1b2e65a
parent 435182 f13e90d496cf1bc6dfc4fd398da33e4afe785bde
child 536343 74b4dd1d94748c84083907a5ab116628e8dd3239
push id35080
push userktomlinson@mozilla.com
push dateTue, 08 Nov 2016 22:22:27 +0000
reviewerslsalzman
bugs1316165
milestone52.0a1
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;