From: Joel Rosdahl Date: Mon, 21 Oct 2024 18:30:05 +0000 (+0200) Subject: refactor: Properly move fds into execute() X-Git-Tag: v4.11~60 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=12495722853ddd30e576cbac9eb0aed377b339a4;p=thirdparty%2Fccache.git refactor: Properly move fds into execute() C++ Core Guidelines F.18 --- diff --git a/src/ccache/execute.cpp b/src/ccache/execute.cpp index 7ed359cc..fd6c7bdf 100644 --- a/src/ccache/execute.cpp +++ b/src/ccache/execute.cpp @@ -300,13 +300,16 @@ execute(Context& ctx, { LOG("Executing {}", util::format_argv_for_logging(argv)); + util::Fd out(std::move(fd_out)); + util::Fd err(std::move(fd_err)); + posix_spawn_file_actions_t fa; CHECK_LIB_CALL(posix_spawn_file_actions_init, &fa); - CHECK_LIB_CALL(posix_spawn_file_actions_adddup2, &fa, *fd_out, STDOUT_FILENO); - CHECK_LIB_CALL(posix_spawn_file_actions_addclose, &fa, *fd_out); - CHECK_LIB_CALL(posix_spawn_file_actions_adddup2, &fa, *fd_err, STDERR_FILENO); - CHECK_LIB_CALL(posix_spawn_file_actions_addclose, &fa, *fd_err); + CHECK_LIB_CALL(posix_spawn_file_actions_adddup2, &fa, *out, STDOUT_FILENO); + CHECK_LIB_CALL(posix_spawn_file_actions_addclose, &fa, *out); + CHECK_LIB_CALL(posix_spawn_file_actions_adddup2, &fa, *err, STDERR_FILENO); + CHECK_LIB_CALL(posix_spawn_file_actions_addclose, &fa, *err); int result; { @@ -321,8 +324,8 @@ execute(Context& ctx, } posix_spawn_file_actions_destroy(&fa); - fd_out.close(); - fd_err.close(); + out.close(); + err.close(); if (result != 0) { return -1;