I have this code:
std::vector<std::string> args_ {"./test_script.sh"};
pid_t child_pid = fork();
switch (child_pid)
{
case 0:
{
// Child process
char ** args = new char*[args_.size() + 1];
for(size_t i = 0; i < args_.size(); ++i){
args[i] = new char[args_[i].size() + 1];
strcpy(args[i], args_[i].c_str());
}
args[args_.size()] = NULL;
execv(args[0], const_cast<char**>(args));
}
Is it OK to no free the allocated memory? as the child process will eventually end and the OS will reclaim the memory? and If I would like to free it anyways, how can I do it?
Thanks,