process: free argv allocations on execvp failure

This commit is contained in:
B2krobbery 2026-04-24 13:17:25 +05:30
parent eedd60805c
commit 29840057e9

View file

@ -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]);