diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -51,22 +51,23 @@ static mode_t ConvertOpenOptionsForPOSIXOpen(uint32_t open_options); File() - : IOObject(eFDTypeFile, false), m_descriptor(kInvalidDescriptor), - m_stream(kInvalidStream), m_options(0), m_own_stream(false), - m_is_interactive(eLazyBoolCalculate), + : IOObject(eFDTypeFile), m_descriptor(kInvalidDescriptor), + m_own_descriptor(false), m_stream(kInvalidStream), m_options(0), + m_own_stream(false), m_is_interactive(eLazyBoolCalculate), m_is_real_terminal(eLazyBoolCalculate), m_supports_colors(eLazyBoolCalculate) {} File(FILE *fh, bool transfer_ownership) - : IOObject(eFDTypeFile, false), m_descriptor(kInvalidDescriptor), - m_stream(fh), m_options(0), m_own_stream(transfer_ownership), - m_is_interactive(eLazyBoolCalculate), + : IOObject(eFDTypeFile), m_descriptor(kInvalidDescriptor), + m_own_descriptor(false), m_stream(fh), m_options(0), + m_own_stream(transfer_ownership), m_is_interactive(eLazyBoolCalculate), m_is_real_terminal(eLazyBoolCalculate), m_supports_colors(eLazyBoolCalculate) {} File(int fd, uint32_t options, bool transfer_ownership) - : IOObject(eFDTypeFile, transfer_ownership), m_descriptor(fd), - m_stream(kInvalidStream), m_options(options), m_own_stream(false), + : IOObject(eFDTypeFile), m_descriptor(fd), + m_own_descriptor(transfer_ownership), m_stream(kInvalidStream), + m_options(options), m_own_stream(false), m_is_interactive(eLazyBoolCalculate), m_is_real_terminal(eLazyBoolCalculate) {} @@ -339,6 +340,7 @@ // Member variables int m_descriptor; + bool m_own_descriptor; FILE *m_stream; uint32_t m_options; bool m_own_stream; diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -122,6 +122,7 @@ SocketProtocol m_protocol; NativeSocket m_socket; bool m_child_processes_inherit; + bool m_should_close_fd; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Utility/IOObject.h b/lldb/include/lldb/Utility/IOObject.h --- a/lldb/include/lldb/Utility/IOObject.h +++ b/lldb/include/lldb/Utility/IOObject.h @@ -29,8 +29,7 @@ typedef int WaitableHandle; static const WaitableHandle kInvalidHandleValue; - IOObject(FDType type, bool should_close) - : m_fd_type(type), m_should_close_fd(should_close) {} + IOObject(FDType type) : m_fd_type(type) {} virtual ~IOObject(); virtual Status Read(void *buf, size_t &num_bytes) = 0; @@ -44,8 +43,6 @@ protected: FDType m_fd_type; - bool m_should_close_fd; // True if this class should close the file descriptor - // when it goes away. private: DISALLOW_COPY_AND_ASSIGN(IOObject); diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -98,7 +98,7 @@ if (DescriptorIsValid()) { const char *mode = GetStreamOpenModeFromOptions(m_options); if (mode) { - if (!m_should_close_fd) { + if (!m_own_descriptor) { // We must duplicate the file descriptor if we don't own it because when you // call fdopen, the stream will own the fd #ifdef _WIN32 @@ -106,7 +106,7 @@ #else m_descriptor = dup(GetDescriptor()); #endif - m_should_close_fd = true; + m_own_descriptor = true; } m_stream = @@ -117,7 +117,7 @@ if (m_stream) { m_own_stream = true; - m_should_close_fd = false; + m_own_descriptor = false; } } } @@ -148,7 +148,7 @@ error.SetErrorToErrno(); } - if (DescriptorIsValid() && m_should_close_fd) { + if (DescriptorIsValid() && m_own_descriptor) { if (::close(m_descriptor) != 0) error.SetErrorToErrno(); } @@ -156,7 +156,7 @@ m_stream = kInvalidStream; m_options = 0; m_own_stream = false; - m_should_close_fd = false; + m_own_descriptor = false; m_is_interactive = eLazyBoolCalculate; m_is_real_terminal = eLazyBoolCalculate; return error; diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -74,9 +74,10 @@ Socket::Socket(SocketProtocol protocol, bool should_close, bool child_processes_inherit) - : IOObject(eFDTypeSocket, should_close), m_protocol(protocol), + : IOObject(eFDTypeSocket), m_protocol(protocol), m_socket(kInvalidSocketValue), - m_child_processes_inherit(child_processes_inherit) {} + m_child_processes_inherit(child_processes_inherit), + m_should_close_fd(should_close) {} Socket::~Socket() { Close(); }