Avoid invalid memory access in child process on Android
This commit is contained in:
parent
474a243890
commit
15a3be2dc1
@ -124,6 +124,11 @@ SeparateProcess::~SeparateProcess()
|
||||
dlclose(m_child_handle);
|
||||
m_child_handle = NULL;
|
||||
m_child_abort_proc = NULL;
|
||||
|
||||
for (char* arg : m_child_args)
|
||||
{
|
||||
delete[] arg;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
@ -343,17 +348,20 @@ bool SeparateProcess::createChildProcess(const std::string& exe,
|
||||
|
||||
const std::string exe_file = StringUtils::getBasename(exe);
|
||||
auto rest_argv = StringUtils::split(argument, ' ');
|
||||
|
||||
std::vector<char*> argv;
|
||||
argv.push_back(const_cast<char*>(exe_file.c_str()));
|
||||
|
||||
char* arg = new char[exe_file.size() + 1]();
|
||||
memcpy(arg, exe_file.c_str(), exe_file.size());
|
||||
m_child_args.push_back(arg);
|
||||
|
||||
for (unsigned i = 0; i < rest_argv.size(); i++)
|
||||
{
|
||||
argv.push_back(const_cast<char*>(rest_argv[i].c_str()));
|
||||
char* arg = new char[rest_argv[i].size() + 1]();
|
||||
memcpy(arg, rest_argv[i].c_str(), rest_argv[i].size());
|
||||
m_child_args.push_back(arg);
|
||||
}
|
||||
|
||||
Log::info("SeparateProcess", "Starting main()");
|
||||
m_child_thread = std::thread(main_proc, argv.size(), &argv[0]);
|
||||
m_child_thread = std::thread(main_proc, m_child_args.size(), &m_child_args[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class SeparateProcess
|
||||
{
|
||||
@ -41,6 +42,7 @@ private:
|
||||
void* m_child_handle;
|
||||
void (*m_child_abort_proc)();
|
||||
std::thread m_child_thread;
|
||||
std::vector<char*> m_child_args;
|
||||
#else
|
||||
int m_child_stdin_write = -1;
|
||||
int m_child_stdout_read = -1;
|
||||
|
Loading…
Reference in New Issue
Block a user