Bug 1233275 - Copy environment for IPC using NSPR. r?jld
MozReview-Commit-ID: J2kBklLfnib
--- 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 += "=";