Bug 1193038: Purposely leak StatisticsReport object and suppress the leak report r=glandium,mccr8,njn
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Tue, 18 Aug 2015 19:21:40 +0200
changeset 294881 346b9ee524d1a704ea953ef16237f3d0c7ee56d1
parent 294862 a92e195a3362fa097b6fb8842b44de941e8f333c
child 294882 8d28818620984759e64d3e78dd0c841cf8bba493
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, mccr8, njn
bugs1193038
milestone43.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 1193038: Purposely leak StatisticsReport object and suppress the leak report r=glandium,mccr8,njn
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;
@@ -4340,20 +4339,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;
@@ -4408,17 +4403,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();
@@ -4466,20 +4460,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[])
 {