From 4a749c02b809c79e99bb352fc5003e36a6e1fd43 Mon Sep 17 00:00:00 2001 From: actboy168 Date: Thu, 23 May 2019 09:46:21 +0800 Subject: [PATCH] Fix a fd leak --- include/ghc/filesystem.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 5932be3..a897658 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3115,7 +3115,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options ec = std::error_code(errno, std::system_category()); return false; } - std::shared_ptr guard_out(nullptr, [out](void*) { ::close(out); }); + std::shared_ptr guard_in(nullptr, [in](void*) { ::close(in); }); int mode = O_CREAT | O_WRONLY | O_TRUNC; if (!overwrite) { mode |= O_EXCL; @@ -3124,7 +3124,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options ec = std::error_code(errno, std::system_category()); return false; } - std::shared_ptr guard_in(nullptr, [in](void*) { ::close(in); }); + std::shared_ptr guard_out(nullptr, [out](void*) { ::close(out); }); ssize_t br, bw; while ((br = ::read(in, buffer.data(), buffer.size())) > 0) { int offset = 0;