From 5cbbfd5c8a4737411c57db61073aa919d884e37d Mon Sep 17 00:00:00 2001 From: cptpcrd <31829097+cptpcrd@users.noreply.github.com> Date: Sun, 21 May 2023 12:15:49 -0400 Subject: [PATCH] Close pipe if fork() fails when spawning processes Prevents potential file descriptor leakage, albeit in a bit of an edge case. --- include/util/command.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/util/command.hpp b/include/util/command.hpp index eff9581..fe0543d 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -82,6 +82,8 @@ inline FILE* open(const std::string& cmd, int& pid) { if (child_pid < 0) { spdlog::error("Unable to exec cmd {}, error {}", cmd.c_str(), strerror(errno)); + ::close(fd[0]); + ::close(fd[1]); return nullptr; }