Commit 3f939986 authored by Victor Stinner's avatar Victor Stinner

imaplib: IMAP4 constructor closes the socket on error

Fix a ResourceWarning(unclosed socket) if an exception is raised in the
constructor after the creation of the socket. Patch written by Nadeem Vawda.
parent 2693ac3d
......@@ -169,6 +169,17 @@ class IMAP4:
self.open(host, port)
try:
self._connect()
except Exception:
try:
self.shutdown()
except socket.error:
pass
raise
def _connect(self):
# Create unique tag for this session,
# and compile tagged response matcher.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment