Process working directory not always setup

This is a fairly subtle bug: We were implicitly creating a temporary std::string object and requesting c_str from this object.

This C string’s lifetime was that of the temporary std::string, and as we did a lot of std::string creation in the following line, with the new libc++, there was a good chance that the temporary string buffer would be re-used and so, our working directory would be set to a bogus value.

This closes issue #329.
This commit is contained in:
Allan Odgaard
2012-08-30 15:44:50 +02:00
parent 4aa5581cfd
commit 4e2b5f91ca

View File

@@ -159,7 +159,8 @@ namespace oak
output_fd = outputPipe[0];
error_fd = errorPipe[0];
char const* workingDir = (environment.find("PWD") != environment.end() ? environment["PWD"] : path::temp()).c_str();
std::string const wdString = environment.find("PWD") != environment.end() ? environment["PWD"] : path::temp();
char const* workingDir = wdString.c_str();
oak::c_array env(environment);
process_id = vfork();