mirror of
https://github.com/hyprwm/hyprutils.git
synced 2026-05-07 03:08:01 +02:00
process: free argv allocations on execvp failure
This commit is contained in:
parent
eedd60805c
commit
29840057e9
1 changed files with 8 additions and 3 deletions
|
|
@ -66,7 +66,7 @@ bool Hyprutils::OS::CProcess::runSync() {
|
|||
std::vector<char*> argsC;
|
||||
argsC.emplace_back(strdup(m_impl->binary.c_str()));
|
||||
for (auto& arg : m_impl->args) {
|
||||
// TODO: does this leak? Can we just pipe c_str() as the strings won't be realloc'd?
|
||||
// Arguments are duplicated for execvp; if execvp fails, they must be freed.
|
||||
argsC.emplace_back(strdup(arg.c_str()));
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +77,13 @@ bool Hyprutils::OS::CProcess::runSync() {
|
|||
setenv(n.c_str(), v.c_str(), 1);
|
||||
}
|
||||
|
||||
execvp(m_impl->binary.c_str(), argsC.data());
|
||||
exit(1);
|
||||
if (execvp(m_impl->binary.c_str(), argsC.data()) == -1) {
|
||||
for (auto ptr : argsC) {
|
||||
if (ptr)
|
||||
free(ptr);
|
||||
}
|
||||
_exit(1);
|
||||
}
|
||||
} else {
|
||||
// parent
|
||||
close(outPipe[1]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue