================
@@ -378,7 +378,10 @@ Status NativeFile::Close() {
           m_options & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly |
                        File::eOpenOptionReadWrite);
 
-      if (rw == eOpenOptionWriteOnly || rw == eOpenOptionReadWrite) {
+      // If the stream is writable, and has not already been closed, flush
+      // it.
+      if ((rw == eOpenOptionWriteOnly || rw == eOpenOptionReadWrite) &&
+          (m_stream->_flags != m_stream->_fileno)) {
----------------
ashgti wrote:

Also, there is another issue with the test closing the file another time. The 
`PseudoTerminal pty` is not releasing the file descriptors, so it will ALSO 
close the files under the hood or try to call `close(fd)` when its destroyed, 
which is the same underlying FD that the `std::unique_ptr<FilePointer> 
_el_secondary_file`  is pointing to. So, we're also closing the file out from 
under the libc `FILE*` pointer or we're closing the FD multiple times (which is 
probably returning -1 with errno == EBADF if I had to guess).

https://github.com/llvm/llvm-project/pull/169088
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to