[Lldb-commits] [PATCH] D18459: Fix FILE * leak in Python API
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 24 15:16:09 PDT 2016
zturner added a comment.
const char *mode = GetStreamOpenModeFromOptions (m_options);
// We must duplicate the file descriptor if we don't own it because
// when you call fdopen, the stream will own the fd
m_descriptor = ::_dup(GetDescriptor());
m_descriptor = dup(GetDescriptor());
m_should_close_fd = true;
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
m_own_stream = true;
m_should_close_fd = false;
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?
More information about the lldb-commits