diff --git a/toolkit/crashreporter/client/crashreporter.cpp b/toolkit/crashreporter/client/crashreporter.cpp index eaf67e2b042..ce2d854c922 100644 --- a/toolkit/crashreporter/client/crashreporter.cpp +++ b/toolkit/crashreporter/client/crashreporter.cpp @@ -300,6 +300,7 @@ int main(int argc, const char** argv) while (param && *param) { restartArgs.push_back(param); + paramName.str(""); paramName << "MOZ_CRASHREPORTER_RESTART_ARG_" << i++; param = getenv(paramName.str().c_str()); }; diff --git a/toolkit/crashreporter/nsExceptionHandler.cpp b/toolkit/crashreporter/nsExceptionHandler.cpp index 12402780768..53ec8ccfe08 100755 --- a/toolkit/crashreporter/nsExceptionHandler.cpp +++ b/toolkit/crashreporter/nsExceptionHandler.cpp @@ -419,12 +419,20 @@ SetRestartArgs(int argc, char **argv) { int i; nsCAutoString envVar; + char *env; for (i = 0; i < argc; i++) { envVar = "MOZ_CRASHREPORTER_RESTART_ARG_"; envVar.AppendInt(i); envVar += "="; envVar += argv[i]; - PR_SetEnv(envVar.get()); + + // PR_SetEnv() wants the string to be available for the lifetime + // of the app, so dup it here + env = ToNewCString(envVar); + if (!env) + return NS_ERROR_OUT_OF_MEMORY; + + PR_SetEnv(env); } // make sure the arg list is terminated @@ -432,7 +440,13 @@ SetRestartArgs(int argc, char **argv) envVar.AppendInt(i); envVar += "="; - PR_SetEnv(envVar.get()); + // PR_SetEnv() wants the string to be available for the lifetime + // of the app, so dup it here + env = ToNewCString(envVar); + if (!env) + return NS_ERROR_OUT_OF_MEMORY; + + PR_SetEnv(env); return NS_OK; }