Bug 1193038 - Purposely leak StatisticsReport object and suppress the leak report. r=glandium,mccr8,njn, a=sylvestre
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Tue, 18 Aug 2015 19:21:40 +0200
changeset 289403 48b17faad125691454ebba9bdef0a5def9128f11
parent 289402 4b731bf345d7330bd094a1639c5ac846c13ce05f
child 289404 b0a5e4576b03c7fb70d30504d71929ccfaa41022
push id5109
push usercbook@mozilla.com
push dateTue, 29 Sep 2015 10:00:36 +0000
treeherdermozilla-beta@f84537028ef2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, mccr8, njn, sylvestre
bugs1193038
milestone42.0
Bug 1193038 - Purposely leak StatisticsReport object and suppress the leak report. r=glandium,mccr8,njn, a=sylvestre
build/valgrind/cross-architecture.sup
toolkit/xre/nsAppRunner.cpp
--- a/build/valgrind/cross-architecture.sup
+++ b/build/valgrind/cross-architecture.sup
@@ -29,16 +29,25 @@
    PR_SetEnv requires its argument to be leaked, but does not appear on stacks. (See bug 793548.)
    Memcheck:Leak
    fun:malloc
    ...
    fun:_Z12ToNewCStringRK19nsACString_internal
    fun:_ZN13CrashReporter14SetupExtraDataEP7nsIFileRK19nsACString_internal
    ...
 }
+{
+   We purposely leak the StatisticsReporter object
+   Memcheck:Leak
+   fun:malloc
+   fun:moz_xmalloc
+   fun:operator new
+   fun:_Z21XRE_CreateStatsObjectv
+   ...
+}
 
 ####################################
 #  Leaks in third party libraries  #
 ####################################
 
 {
    See bug 793535
    Memcheck:Leak
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/ChaosMode.h"
 #include "mozilla/IOInterposer.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Poison.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/MemoryChecking.h"
 
 #include "nsAppRunner.h"
 #include "mozilla/AppData.h"
 #if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
 #include "nsUpdateDriver.h"
 #endif
 #include "ProfileReset.h"
 
@@ -3067,17 +3068,16 @@ public:
 #endif
 #if defined(MOZ_WIDGET_GTK)
     , mGdkDisplay(nullptr)
 #endif
   {};
 
   ~XREMain() {
     mScopedXPCOM = nullptr;
-    mStatisticsRecorder = nullptr;
     mAppData = nullptr;
   }
 
   int XRE_main(int argc, char* argv[], const nsXREAppData* aAppData);
   int XRE_mainInit(bool* aExitFlag);
   int XRE_mainStartup(bool* aExitFlag);
   nsresult XRE_mainRun();
   
@@ -3086,17 +3086,16 @@ public:
   nsCOMPtr<nsIFile> mProfD;
   nsCOMPtr<nsIFile> mProfLD;
   nsCOMPtr<nsIProfileLock> mProfileLock;
 #ifdef MOZ_ENABLE_XREMOTE
   nsCOMPtr<nsIRemoteService> mRemoteService;
 #endif
 
   UniquePtr<ScopedXPCOMStartup> mScopedXPCOM;
-  UniquePtr<base::StatisticsRecorder> mStatisticsRecorder;
   nsAutoPtr<mozilla::ScopedAppData> mAppData;
 
   nsXREDirProvider mDirProvider;
   nsAutoCString mProfileName;
   nsAutoCString mDesktopStartupID;
 
   bool mStartOffline;
   bool mShuttingDown;
@@ -4336,20 +4335,16 @@ XREMain::XRE_main(int argc, char* argv[]
 
   nsresult rv = NS_OK;
 
   gArgc = argc;
   gArgv = argv;
 
   NS_ENSURE_TRUE(aAppData, 2);
 
-  // A initializer to initialize histogram collection, a chromium
-  // thing used by Telemetry.
-  mStatisticsRecorder = MakeUnique<base::StatisticsRecorder>();
-
   mAppData = new ScopedAppData(aAppData);
   if (!mAppData)
     return 1;
   if (!mAppData->remotingName) {
     SetAllocatedString(mAppData->remotingName, mAppData->name);
   }
   // used throughout this file
   gAppData = mAppData;
@@ -4404,17 +4399,16 @@ XREMain::XRE_main(int argc, char* argv[]
     // shut down the x remote proxy window
     if (mRemoteService) {
       mRemoteService->Shutdown();
     }
 #endif /* MOZ_ENABLE_XREMOTE */
   }
 
   mScopedXPCOM = nullptr;
-  mStatisticsRecorder = nullptr;
 
   // unlock the profile after ScopedXPCOMStartup object (xpcom) 
   // has gone out of scope.  see bug #386739 for more details
   mProfileLock->Unlock();
   gProfileLock = nullptr;
 
 #if defined(MOZ_WIDGET_QT)
   nsQAppInstance::Release();
@@ -4462,20 +4456,34 @@ XREMain::XRE_main(int argc, char* argv[]
   return NS_FAILED(rv) ? 1 : 0;
 }
 
 void
 XRE_StopLateWriteChecks(void) {
   mozilla::StopLateWriteChecks();
 }
 
+// Separate stub function to let us specifically suppress it in Valgrind
+void
+XRE_CreateStatsObject()
+{
+  // A initializer to initialize histogram collection, a chromium
+  // thing used by Telemetry (and effectively a global; it's all static).
+  // Note: purposely leaked
+  base::StatisticsRecorder* statistics_recorder = new base::StatisticsRecorder();
+  MOZ_LSAN_INTENTIONALLY_LEAK_OBJECT(statistics_recorder);
+  unused << statistics_recorder;
+}
+
 int
 XRE_main(int argc, char* argv[], const nsXREAppData* aAppData, uint32_t aFlags)
 {
   XREMain main;
+
+  XRE_CreateStatsObject();
   int result = main.XRE_main(argc, argv, aAppData);
   mozilla::RecordShutdownEndTimeStamp();
   return result;
 }
 
 nsresult
 XRE_InitCommandLine(int aArgc, char* aArgv[])
 {