Bug 1233275 - Copy environment for IPC using NSPR. r=jld
authorJan Beich <jbeich@FreeBSD.org>
Thu, 24 Mar 2016 17:52:40 +0000
changeset 290545 84f912382f78363398ad538abbe0fadb5100020a
parent 290544 7ca9567ed5c7f2055b9911dee5b41e62398361c7
child 290546 7a8fb7e6f6f915ad87eba700b4f36ff0c0d5ecab
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1233275
milestone48.0a1
Bug 1233275 - Copy environment for IPC using NSPR. r=jld MozReview-Commit-ID: J2kBklLfnib
ipc/chromium/src/base/process_util_bsd.cc
--- a/ipc/chromium/src/base/process_util_bsd.cc
+++ b/ipc/chromium/src/base/process_util_bsd.cc
@@ -7,20 +7,19 @@
 #include "base/process_util.h"
 
 #include <fcntl.h>
 #include <spawn.h>
 #include <sys/wait.h>
 
 #include <string>
 
+#include "nspr.h"
 #include "base/eintr_wrapper.h"
 
-extern "C" char **environ __attribute__((__visibility__("default")));
-
 namespace base {
 
 void FreeEnvVarsArray(char* array[], int length)
 {
   for (int i = 0; i < length; i++) {
     free(array[i]);
   }
   delete[] array;
@@ -61,25 +60,27 @@ bool LaunchApp(const std::vector<std::st
   // as close-on-exec.
   SetAllFDsToCloseOnExec();
 
   // Copy environment to a new char array and add the variables
   // in env_vars_to_set.
   // Existing variables are overwritten by env_vars_to_set.
   int pos = 0;
   environment_map combined_env_vars = env_vars_to_set;
+  char **environ = PR_DuplicateEnvironment();
   while(environ[pos] != NULL) {
     std::string varString = environ[pos];
     std::string varName = varString.substr(0, varString.find_first_of('='));
     std::string varValue = varString.substr(varString.find_first_of('=') + 1);
     if (combined_env_vars.find(varName) == combined_env_vars.end()) {
       combined_env_vars[varName] = varValue;
     }
-    pos++;
+    PR_Free(environ[pos++]);
   }
+  PR_Free(environ);
   int varsLen = combined_env_vars.size() + 1;
 
   char** vars = new char*[varsLen];
   int i = 0;
   for (environment_map::const_iterator it = combined_env_vars.begin();
        it != combined_env_vars.end(); ++it) {
     std::string entry(it->first);
     entry += "=";