Bug 1275117 - Fix static strings leaks when mozlogging is on. r=jduell
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 31 May 2016 08:11:00 -0400
changeset 339479 e5c0280538897f5b65cbef0b8c7e6af07c092c56
parent 339478 25abbc9e62370b99ff495fee44c6145c38ae4656
child 339480 14c8ec387dd2ac2ed8f4670e07d68b67fb8b0f72
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs1275117
milestone49.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 1275117 - Fix static strings leaks when mozlogging is on. r=jduell
ipc/glue/GeckoChildProcessHost.cpp
ipc/glue/GeckoChildProcessHost.h
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -518,52 +518,48 @@ GeckoChildProcessHost::PerformAsyncLaunc
 {
   // If NSPR log files are not requested, we're done.
   const char* origNSPRLogName = PR_GetEnv("NSPR_LOG_FILE");
   const char* origMozLogName = PR_GetEnv("MOZ_LOG_FILE");
   if (!origNSPRLogName && !origMozLogName) {
     return PerformAsyncLaunchInternal(aExtraOpts, arch);
   }
 
-  ++mChildCounter;
-
-  // remember original value so we can restore it.
   // - Note: this code is not called re-entrantly, nor are restoreOrig*LogName
   //   or mChildCounter touched by any other thread, so this is safe.
-  static nsAutoCString restoreOrigNSPRLogName;
-  static nsAutoCString restoreOrigMozLogName;
+  ++mChildCounter;
 
   // Must keep these on the same stack where from we call PerformAsyncLaunchInternal
   // so that PR_DuplicateEnvironment() still sees a valid memory.
   nsAutoCString nsprLogName;
   nsAutoCString mozLogName;
 
   if (origNSPRLogName) {
-    if (restoreOrigNSPRLogName.IsEmpty()) {
-      restoreOrigNSPRLogName.AssignLiteral("NSPR_LOG_FILE=");
-      restoreOrigNSPRLogName.Append(origNSPRLogName);
+    if (mRestoreOrigNSPRLogName.IsEmpty()) {
+      mRestoreOrigNSPRLogName.AssignLiteral("NSPR_LOG_FILE=");
+      mRestoreOrigNSPRLogName.Append(origNSPRLogName);
     }
     SetChildLogName("NSPR_LOG_FILE=", origNSPRLogName, nsprLogName);
   }
   if (origMozLogName) {
-    if (restoreOrigMozLogName.IsEmpty()) {
-      restoreOrigMozLogName.AssignLiteral("MOZ_LOG_FILE=");
-      restoreOrigMozLogName.Append(origMozLogName);
+    if (mRestoreOrigMozLogName.IsEmpty()) {
+      mRestoreOrigMozLogName.AssignLiteral("MOZ_LOG_FILE=");
+      mRestoreOrigMozLogName.Append(origMozLogName);
     }
     SetChildLogName("MOZ_LOG_FILE=", origMozLogName, mozLogName);
   }
 
   bool retval = PerformAsyncLaunchInternal(aExtraOpts, arch);
 
   // Revert to original value
   if (origNSPRLogName) {
-    PR_SetEnv(restoreOrigNSPRLogName.get());
+    PR_SetEnv(mRestoreOrigNSPRLogName.get());
   }
   if (origMozLogName) {
-    PR_SetEnv(restoreOrigMozLogName.get());
+    PR_SetEnv(mRestoreOrigMozLogName.get());
   }
 
   return retval;
 }
 
 bool
 GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector<std::string> aExtraOpts,
                                              base::ProcessArchitecture aArch)
--- a/ipc/glue/GeckoChildProcessHost.h
+++ b/ipc/glue/GeckoChildProcessHost.h
@@ -215,16 +215,22 @@ private:
   //
   // FIXME/cjones: this strongly indicates bad design.  Shame on us.
   std::queue<IPC::Message> mQueue;
 
   // This tracks how many actors are associated with this process that require
   // it to stay alive and have not yet been destroyed.
   Atomic<int32_t> mAssociatedActors;
 
+  // Remember original env values so we can restore it (there is no other
+  // simple way how to change environment of a child process than to modify
+  // the current environment).
+  nsCString mRestoreOrigNSPRLogName;
+  nsCString mRestoreOrigMozLogName;
+
   static uint32_t sNextUniqueID;
 };
 
 #ifdef MOZ_NUWA_PROCESS
 class GeckoExistingProcessHost final : public GeckoChildProcessHost
 {
 public:
   GeckoExistingProcessHost(GeckoProcessType aProcessType,