Bug 1475949 - Fix DEAD_STORE issues in XRemoteClient. r=jhorak
authorRobert Bartlensky <rbartlensky@mozilla.com>
Tue, 17 Jul 2018 11:45:33 +0100
changeset 427497 a9c6b8e2e0ea
parent 427496 b3cfdf00c7f2
child 427498 564e53c57905
push id66656
push userapavel@mozilla.com
push dateFri, 20 Jul 2018 15:06:14 +0000
treeherderautoland@a9c6b8e2e0ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1475949
milestone63.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 1475949 - Fix DEAD_STORE issues in XRemoteClient. r=jhorak MozReview-Commit-ID: IDFaUR2gK4R
widget/xremoteclient/XRemoteClient.cpp
--- a/widget/xremoteclient/XRemoteClient.cpp
+++ b/widget/xremoteclient/XRemoteClient.cpp
@@ -4,16 +4,17 @@
 /* vim:set ts=8 sw=2 et cindent: */
 /* 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/. */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Sprintf.h"
+#include "mozilla/Unused.h"
 #include "XRemoteClient.h"
 #include "RemoteUtils.h"
 #include "plstr.h"
 #include "prsystem.h"
 #include "mozilla/Logging.h"
 #include "prenv.h"
 #include "prdtoa.h"
 #include <stdlib.h>
@@ -36,26 +37,27 @@
 
 #ifdef IS_BIG_ENDIAN
 #define TO_LITTLE_ENDIAN32(x) \
     ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
     (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
 #else
 #define TO_LITTLE_ENDIAN32(x) (x)
 #endif
-    
+
 #ifndef MAX_PATH
 #ifdef PATH_MAX
 #define MAX_PATH PATH_MAX
 #else
 #define MAX_PATH 1024
 #endif
 #endif
 
 using mozilla::LogLevel;
+using mozilla::Unused;
 
 static mozilla::LazyLogModule sRemoteLm("XRemoteClient");
 
 static int (*sOldHandler)(Display *, XErrorEvent *);
 static bool sGotBadWindow;
 
 XRemoteClient::XRemoteClient()
 {
@@ -113,17 +115,17 @@ XRemoteClient::Init()
   int i = 0;
   mMozVersionAtom  = XAtoms[i++];
   mMozLockAtom     = XAtoms[i++];
   mMozResponseAtom = XAtoms[i++];
   mMozWMStateAtom  = XAtoms[i++];
   mMozUserAtom     = XAtoms[i++];
   mMozProfileAtom  = XAtoms[i++];
   mMozProgramAtom  = XAtoms[i++];
-  mMozCommandLineAtom = XAtoms[i++];
+  mMozCommandLineAtom = XAtoms[i];
 
   mInitialized = true;
 
   return NS_OK;
 }
 
 void
 XRemoteClient::Shutdown (void)
@@ -145,19 +147,19 @@ XRemoteClient::Shutdown (void)
 
 static int
 HandleBadWindow(Display *display, XErrorEvent *event)
 {
   if (event->error_code == BadWindow) {
     sGotBadWindow = true;
     return 0; // ignored
   }
-  
+
     return (*sOldHandler)(display, event);
-  
+
 }
 
 nsresult
 XRemoteClient::SendCommandLine (const char *aProgram, const char *aUsername,
                                 const char *aProfile,
                                 int32_t argc, char **argv,
                                 const char* aDesktopStartupID,
                                 char **aResponse, bool *aWindowFound)
@@ -247,21 +249,21 @@ XRemoteClient::CheckChildren(Window aWin
   Window *children;
   unsigned int nchildren;
   unsigned int i;
   Atom type = None;
   int format;
   unsigned long nitems, after;
   unsigned char *data;
   Window retval = None;
-  
+
   if (!XQueryTree(mDisplay, aWindow, &root, &parent, &children,
 		  &nchildren))
     return None;
-  
+
   // scan the list first before recursing into the list of windows
   // which can get quite deep.
   for (i=0; !retval && (i < nchildren); i++) {
     XGetWindowProperty(mDisplay, children[i], mMozWMStateAtom,
 		       0, 0, False, AnyPropertyType, &type, &format,
 		       &nitems, &after, &data);
     if (type) {
       XFree(data);
@@ -285,27 +287,27 @@ XRemoteClient::GetLock(Window aWindow, b
 {
   bool locked = false;
   bool waited = false;
   *aDestroyed = false;
 
   nsresult rv = NS_OK;
 
   if (!mLockData) {
-    
+
     char pidstr[32];
     char sysinfobuf[SYS_INFO_BUFFER_LENGTH];
     SprintfLiteral(pidstr, "pid%d@", getpid());
     PRStatus status;
     status = PR_GetSystemInfo(PR_SI_HOSTNAME, sysinfobuf,
 			      SYS_INFO_BUFFER_LENGTH);
     if (status != PR_SUCCESS) {
       return NS_ERROR_FAILURE;
     }
-    
+
     // allocate enough space for the string plus the terminating
     // char
     mLockData = (char *)malloc(strlen(pidstr) + strlen(sysinfobuf) + 1);
     if (!mLockData)
       return NS_ERROR_OUT_OF_MEMORY;
 
     strcpy(mLockData, pidstr);
     if (!strcat(mLockData, sysinfobuf))
@@ -348,17 +350,17 @@ XRemoteClient::GetLock(Window aWindow, b
 
     XUngrabServer(mDisplay);
     XFlush(mDisplay); // ungrab now!
 
     if (!locked && !NS_FAILED(rv)) {
       /* We tried to grab the lock this time, and failed because someone
 	 else is holding it already.  So, wait for a PropertyDelete event
 	 to come in, and try again. */
-      MOZ_LOG(sRemoteLm, LogLevel::Debug, 
+      MOZ_LOG(sRemoteLm, LogLevel::Debug,
 	     ("window 0x%x is locked by %s; waiting...\n",
 	      (unsigned int) aWindow, data));
       waited = True;
       while (true) {
 	XEvent event;
 	int select_retval;
 	fd_set select_set;
 	struct timeval delay;
@@ -467,22 +469,22 @@ XRemoteClient::FindBestWindow(const char
     if (status != Success || type == None)
       continue;
 
     // If someone passed in a program name, check it against this one
     // unless it's "any" in which case, we don't care.  If someone did
     // pass in a program name and this window doesn't support that
     // protocol, we don't include it in our list.
     if (aProgram && strcmp(aProgram, "any")) {
-        status = XGetWindowProperty(mDisplay, w, mMozProgramAtom,
-                                    0, (65536 / sizeof(long)),
-                                    False, XA_STRING,
-                                    &type, &format, &nitems, &bytesafter,
-                                    &data_return);
-        
+        Unused << XGetWindowProperty(mDisplay, w, mMozProgramAtom,
+                                     0, (65536 / sizeof(long)),
+                                     False, XA_STRING,
+                                     &type, &format, &nitems, &bytesafter,
+                                     &data_return);
+
         // If the return name is not the same as what someone passed in,
         // we don't want this window.
         if (data_return) {
             if (strcmp(aProgram, (const char *)data_return)) {
                 XFree(data_return);
                 continue;
             }
 
@@ -502,21 +504,21 @@ XRemoteClient::FindBestWindow(const char
     if (aUsername) {
       username = aUsername;
     }
     else {
       username = PR_GetEnv("LOGNAME");
     }
 
     if (username) {
-        status = XGetWindowProperty(mDisplay, w, mMozUserAtom,
-                                    0, (65536 / sizeof(long)),
-                                    False, XA_STRING,
-                                    &type, &format, &nitems, &bytesafter,
-                                    &data_return);
+        Unused << XGetWindowProperty(mDisplay, w, mMozUserAtom,
+                                     0, (65536 / sizeof(long)),
+                                     False, XA_STRING,
+                                     &type, &format, &nitems, &bytesafter,
+                                     &data_return);
 
         // if there's a username compare it with what we have
         if (data_return) {
             // If the IDs aren't equal, we don't want this window.
             if (strcmp(username, (const char *)data_return)) {
                 XFree(data_return);
                 continue;
             }
@@ -524,21 +526,21 @@ XRemoteClient::FindBestWindow(const char
             XFree(data_return);
         }
     }
 
     // Check to see if there's a profile name on this window.  If
     // there is, then we need to make sure it matches what someone
     // passed in.
     if (aProfile) {
-        status = XGetWindowProperty(mDisplay, w, mMozProfileAtom,
-                                    0, (65536 / sizeof(long)),
-                                    False, XA_STRING,
-                                    &type, &format, &nitems, &bytesafter,
-                                    &data_return);
+        Unused << XGetWindowProperty(mDisplay, w, mMozProfileAtom,
+                                     0, (65536 / sizeof(long)),
+                                     False, XA_STRING,
+                                     &type, &format, &nitems, &bytesafter,
+                                     &data_return);
 
         // If there's a profile compare it with what we have
         if (data_return) {
             // If the profiles aren't equal, we don't want this window.
             if (strcmp(aProfile, (const char *)data_return)) {
                 XFree(data_return);
                 continue;
             }
@@ -615,17 +617,17 @@ XRemoteClient::DoSendCommandLine(Window 
                                            &commandLineLength);
   XChangeProperty (mDisplay, aWindow, mMozCommandLineAtom, XA_STRING, 8,
                    PropModeReplace, (unsigned char *) commandLine,
                    commandLineLength);
   free(commandLine);
 
   if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandLineAtom))
     return NS_ERROR_FAILURE;
-  
+
   return NS_OK;
 }
 
 bool
 XRemoteClient::WaitForResponse(Window aWindow, char **aResponse,
                                bool *aDestroyed, Atom aCommandAtom)
 {
   bool done = false;
@@ -728,13 +730,13 @@ XRemoteClient::WaitForResponse(Window aW
              event.xproperty.window == aWindow &&
              event.xproperty.state == PropertyDelete &&
              event.xproperty.atom == aCommandAtom) {
       MOZ_LOG(sRemoteLm, LogLevel::Debug,
              ("(server 0x%x has accepted "
               MOZILLA_COMMANDLINE_PROP ".)\n",
               (unsigned int) aWindow));
     }
-    
+
   }
 
   return accepted;
 }