[libcxx-commits] [libcxx] 08b4cc5 - [libcxx] Avoid double frees of file descriptors in the fallback ifstream/ofstream codepath

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 2 23:33:32 PST 2020


Author: Martin Storsjö
Date: 2020-11-03T09:32:52+02:00
New Revision: 08b4cc5e0d2625e85ed4af9aad17ccc0876e3bd3

URL: https://github.com/llvm/llvm-project/commit/08b4cc5e0d2625e85ed4af9aad17ccc0876e3bd3
DIFF: https://github.com/llvm/llvm-project/commit/08b4cc5e0d2625e85ed4af9aad17ccc0876e3bd3.diff

LOG: [libcxx] Avoid double frees of file descriptors in the fallback ifstream/ofstream codepath

So far, most actual uses of libc++ std::filesystem probably use
the sendfile or fcopyfile implementations.

Differential Revision: https://reviews.llvm.org/D90601

Added: 
    

Modified: 
    libcxx/src/filesystem/operations.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 788e31b673aa..6a259792477c 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -684,12 +684,14 @@ namespace {
       ec = capture_errno();
       return false;
     }
+    read_fd.fd = -1;
     ofstream out;
     out.__open(write_fd.fd, ios::binary);
     if (!out.is_open()) {
       ec = capture_errno();
       return false;
     }
+    write_fd.fd = -1;
 
     if (in.good() && out.good()) {
       using InIt = istreambuf_iterator<char>;


        


More information about the libcxx-commits mailing list