From fa3992be2dfebe4ab06d753c6ca59bea298e798f Mon Sep 17 00:00:00 2001 From: Visal Vijay <150381094+B2krobbery@users.noreply.github.com> Date: Sun, 26 Apr 2026 01:47:03 +0530 Subject: [PATCH] process: free argv allocations on execvp failure (#106) * process: free argv allocations on execvp failure * fix execvp style --- src/os/Process.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/os/Process.cpp b/src/os/Process.cpp index 335d6b1..b6faf55 100644 --- a/src/os/Process.cpp +++ b/src/os/Process.cpp @@ -66,7 +66,7 @@ bool Hyprutils::OS::CProcess::runSync() { std::vector 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())); } @@ -78,7 +78,12 @@ bool Hyprutils::OS::CProcess::runSync() { } execvp(m_impl->binary.c_str(), argsC.data()); - exit(1); + for (auto ptr : argsC) { + if (ptr) + free(ptr); + } + _exit(1); + } else { // parent close(outPipe[1]);