Bug 1390776 - Put definition and uses of gProgname under #ifdef CRAWL_STACK_ON_SIGSEGV. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 16 Aug 2017 17:17:08 +0900
changeset 647418 a40817994487dfa7b3b52e2efdca2dd90d616b83
parent 647408 e02c5a746b93db7d56461259d4fd85c29dd4c0e9
child 726490 0560951c55650bd24e2715fd9973223b1611eb76
push id74393
push userbmo:mh+mozilla@glandium.org
push dateWed, 16 Aug 2017 09:01:53 +0000
reviewersnjn
bugs1390776
milestone57.0a1
Bug 1390776 - Put definition and uses of gProgname under #ifdef CRAWL_STACK_ON_SIGSEGV. r?njn gProgname is actually never used outside #ifdef CRAWL_STACK_ON_SIGSEGV, and it being defined and filled with a strdup even when not used leads to a (purposeful, but useless) leak. The leak was not detected so far because GCC 4.9 generated a call to PL_strdup followed by a store to gProgname, while GCC 6 keeps the PL_strdup but is smart enough to figure out it doesn't need to store to gProgname (and to not keep space for that variable). So with GCC 4.9, the leak was not considered a leak because it was still reachable, but with GCC 6, it's not reachable anymore, and thus considered as a leak.
toolkit/xre/nsSigHandlers.cpp
--- a/toolkit/xre/nsSigHandlers.cpp
+++ b/toolkit/xre/nsSigHandlers.cpp
@@ -32,18 +32,16 @@
 #endif
 #endif
 
 #if defined(SOLARIS)
 #include <sys/resource.h>
 #include <ucontext.h>
 #endif
 
-static const char* gProgname = "huh?";
-
 // Note: some tests manipulate this value.
 unsigned int _gdb_sleep_duration = 300;
 
 #if defined(LINUX) && defined(DEBUG) && \
       (defined(__i386) || defined(__x86_64) || defined(PPC))
 #define CRAWL_STACK_ON_SIGSEGV
 #endif
 
@@ -55,16 +53,18 @@ unsigned int _gdb_sleep_duration = 300;
 #endif
 
 #if defined(CRAWL_STACK_ON_SIGSEGV)
 
 #include <unistd.h>
 #include "nsISupportsUtils.h"
 #include "mozilla/StackWalk.h"
 
+static const char* gProgname = "huh?";
+
 // NB: keep me up to date with the same variable in
 // ipc/chromium/chrome/common/ipc_channel_posix.cc
 static const int kClientChannelFd = 3;
 
 extern "C" {
 
 static void PrintStackFrame(uint32_t aFrameNumber, void *aPC, void *aSP,
                             void *aClosure)
@@ -223,20 +223,22 @@ static void fpehandler(int signum, sigin
   *mxcsr &= ~SSE_STATUS_FLAGS; /* clear all pending SSE exceptions */
 #endif
 #endif
 }
 #endif
 
 void InstallSignalHandlers(const char *aProgname)
 {
+#if defined(CRAWL_STACK_ON_SIGSEGV)
   const char* tmp = PL_strdup(aProgname);
   if (tmp) {
     gProgname = tmp;
   }
+#endif // CRAWL_STACK_ON_SIGSEGV
 
   const char *gdbSleep = PR_GetEnv("MOZ_GDB_SLEEP");
   if (gdbSleep && *gdbSleep)
   {
     unsigned int s;
     if (1 == sscanf(gdbSleep, "%u", &s)) {
       _gdb_sleep_duration = s;
     }