bug 1316165 ensure xcb_get_input_focus_reply is called to avoid leaking the reply r=lsalzman a=lhenry
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 14 Nov 2016 11:53:58 +1300
changeset 356554 1da2ad7a0924a22c90c71ca24c7d53a7ff9eb9b9
parent 356553 7cb90cec7f297457e088106ba9f6cc58ab5b51be
child 356555 fa8ec97c92580df87d5900565cd1c1c1a98f631c
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman, lhenry
bugs1316165
milestone51.0a2
bug 1316165 ensure xcb_get_input_focus_reply is called to avoid leaking the reply r=lsalzman a=lhenry
widget/nsShmImage.cpp
widget/nsShmImage.h
--- a/widget/nsShmImage.cpp
+++ b/widget/nsShmImage.cpp
@@ -234,38 +234,46 @@ 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();
 }
 
-already_AddRefed<DrawTarget>
-nsShmImage::CreateDrawTarget(const mozilla::LayoutDeviceIntRegion& aRegion)
+// 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()
 {
-  // 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);
-    }
+    xcb_get_input_focus_reply_t* reply =
+      xcb_get_input_focus_reply(mConnection, mSyncRequest, nullptr);
+    free(reply);
     mRequestPending = false;
 
     xcb_generic_error_t* error;
     if ((error = xcb_request_check(mConnection, mPutRequest))) {
       gShmAvailable = false;
       free(error);
       return nullptr;
     }
   }
+}
+
+already_AddRefed<DrawTarget>
+nsShmImage::CreateDrawTarget(const mozilla::LayoutDeviceIntRegion& aRegion)
+{
+  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;