From 4e2b5f91ca947b2b5c79aaef5ec44e65ec080345 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Thu, 30 Aug 2012 15:44:50 +0200 Subject: [PATCH] Process working directory not always setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Frameworks/OakSystem/src/process.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Frameworks/OakSystem/src/process.cc b/Frameworks/OakSystem/src/process.cc index aa12e5a0..ab14f576 100644 --- a/Frameworks/OakSystem/src/process.cc +++ b/Frameworks/OakSystem/src/process.cc @@ -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();