llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: None (cmtice)

<details>
<summary>Changes</summary>

PR/167764 makes sure the access mode for newly created Native files is 
writable. This uncovered a bug in NativeFile::Close where it tries to flush a 
writable file without first checking to make sure the file hasn't already been 
closed. This triggers a bug in some of our code, where it closes a file by 
ovewriting the fields with nonsense values rather than deleting the pointer. 
This PR now checks to make sure this has not been done before trying to flush 
it.

---
Full diff: https://github.com/llvm/llvm-project/pull/169088.diff


1 Files Affected:

- (modified) lldb/source/Host/common/File.cpp (+4-1) 


``````````diff
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index 4fad93fca9ea3..64504421a4d0b 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -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)) {
         if (::fflush(m_stream) == EOF)
           error = Status::FromErrno();
       }

``````````

</details>


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