diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp index c44e1549..54410bf6 100644 --- a/src/platforms/posix/posixChildProcess.cpp +++ b/src/platforms/posix/posixChildProcess.cpp @@ -200,7 +200,7 @@ private: posixChildProcess::posixChildProcess(const utility::file::path& path) : m_processPath(path), m_started(false), - m_stdIn(NULL), m_stdOut(NULL), m_pid(0) + m_stdIn(NULL), m_stdOut(NULL), m_pid(0), m_argArray(NULL) { m_pipe[0] = 0; m_pipe[1] = 0; @@ -222,6 +222,8 @@ posixChildProcess::~posixChildProcess() delete (m_stdIn); delete (m_stdOut); + + delete [] (m_argArray); } @@ -239,11 +241,14 @@ void posixChildProcess::start(const std::vector args, const int flags) // Construct C-style argument array const char** argv = new const char*[args.size() + 2]; + m_argVector = args; // for c_str() pointer to remain valid + m_argArray = argv; // to free later + argv[0] = m_processPath.getLastComponent().getBuffer().c_str(); argv[args.size()] = NULL; - for (unsigned int i = 0 ; i < args.size() ; ++i) - argv[i + 1] = args[i].c_str(); + for (unsigned int i = 0 ; i < m_argVector.size() ; ++i) + argv[i + 1] = m_argVector[i].c_str(); // Create a pipe to communicate with the child process int fd[2]; diff --git a/vmime/platforms/posix/posixChildProcess.hpp b/vmime/platforms/posix/posixChildProcess.hpp index 96d50d5a..0fa15406 100644 --- a/vmime/platforms/posix/posixChildProcess.hpp +++ b/vmime/platforms/posix/posixChildProcess.hpp @@ -54,6 +54,9 @@ private: sigset_t m_oldProcMask; pid_t m_pid; int m_pipe[2]; + + std::vector m_argVector; + const char** m_argArray; };