Bug 1233275 - Copy environment for IPC using NSPR. draft
authorJan Beich <jbeich@FreeBSD.org>
Sun, 20 Dec 2015 09:03:08 +0000
changeset 339840 e7fad7c1d6f36917d2476688d6fa76c53cbc0cb4
parent 339836 f31e566af61cf01e64942646b40f42dbe9495ea2
child 339841 70cd52110fcd34a35d2201841f4a2e89ad8b9093
push id12805
push userjbeich@FreeBSD.org
push dateSun, 13 Mar 2016 10:57:20 +0000
bugs1233275
milestone48.0a1
Bug 1233275 - Copy environment for IPC using NSPR. 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);
   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 += "=";