zturner added a comment.

  if (!StreamIsValid())
  {
      if (DescriptorIsValid())
      {
          const char *mode = GetStreamOpenModeFromOptions (m_options);
          if (mode)
          {
              if (!m_should_close_fd)
              {
                  // 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
                  m_descriptor = ::_dup(GetDescriptor());
  #else
                  m_descriptor = dup(GetDescriptor());
  #endif
                  m_should_close_fd = true;
              }
  
              do
              {
                  m_stream = ::fdopen (m_descriptor, mode);
              } while (m_stream == NULL && errno == EINTR);
  
              // If we got a stream, then we own the stream and should no
              // longer own the descriptor because fclose() will close it for us
  
              if (m_stream)
              {
                  m_own_stream = true;
                  m_should_close_fd = false;
              }
          }
      }
  }
  return m_stream;

If this is successful, the final `if (m_stream)` check passes, and it sets 
`m_own_stream` to `true`.  This means that in the `File` destructor, it will 
call `fclose`.  It doesn't matter that nobody calls `close`, because after 
you've `fdopen`'ed something, you're not supposed to call `close`, only 
`fclose`.

Am I missing something?


http://reviews.llvm.org/D18459



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to