]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Properly move fds into execute()
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 21 Oct 2024 18:30:05 +0000 (20:30 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 22 Oct 2024 16:42:55 +0000 (18:42 +0200)
C++ Core Guidelines F.18

src/ccache/execute.cpp

index 7ed359cc4d474b449448f9dd9a34f4801173ef34..fd6c7bdffef9366440fdcb46e9c2be88b1a20927 100644 (file)
@@ -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;