Merge pull request #20 from actboy168/patch-2

Fix an fd leak
This commit is contained in:
gulrak 2019-05-23 08:37:32 +02:00 committed by GitHub
commit db09380e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<void> guard_out(nullptr, [out](void*) { ::close(out); });
std::shared_ptr<void> 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<void> guard_in(nullptr, [in](void*) { ::close(in); });
std::shared_ptr<void> guard_out(nullptr, [out](void*) { ::close(out); });
ssize_t br, bw;
while ((br = ::read(in, buffer.data(), buffer.size())) > 0) {
int offset = 0;