[libcxx] Avoid double frees of file descriptors in the fallback ifstream/ofstream...
authorMartin Storsjö <martin@martin.st>
Mon, 2 Nov 2020 08:19:42 +0000 (10:19 +0200)
committerMartin Storsjö <martin@martin.st>
Tue, 3 Nov 2020 07:32:52 +0000 (09:32 +0200)
So far, most actual uses of libc++ std::filesystem probably use
the sendfile or fcopyfile implementations.

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

libcxx/src/filesystem/operations.cpp

index 788e31b..6a25979 100644 (file)
@@ -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>;