[Python-checkins] bpo-31234, socket.create_connection(): Fix ref cycle (#3546)

Victor Stinner webhook-mailer at python.org
Wed Sep 13 13:10:13 EDT 2017


https://github.com/python/cpython/commit/acb9fa79fa6453c2bbe3ccfc9cad2837feb90093
commit: acb9fa79fa6453c2bbe3ccfc9cad2837feb90093
branch: master
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-09-13T10:10:10-07:00
summary:

bpo-31234, socket.create_connection(): Fix ref cycle (#3546)

files:
A Misc/NEWS.d/next/Library/2017-09-13-18-05-56.bpo-31234.lGkcPg.rst
M Lib/socket.py

diff --git a/Lib/socket.py b/Lib/socket.py
index 740e71782af..1ada24d3326 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -711,6 +711,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
             if source_address:
                 sock.bind(source_address)
             sock.connect(sa)
+            # Break explicitly a reference cycle
+            err = None
             return sock
 
         except error as _:
diff --git a/Misc/NEWS.d/next/Library/2017-09-13-18-05-56.bpo-31234.lGkcPg.rst b/Misc/NEWS.d/next/Library/2017-09-13-18-05-56.bpo-31234.lGkcPg.rst
new file mode 100644
index 00000000000..e522e8e9527
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-09-13-18-05-56.bpo-31234.lGkcPg.rst
@@ -0,0 +1,2 @@
+socket.create_connection() now fixes manually a reference cycle: clear the
+variable storing the last exception on success.



More information about the Python-checkins mailing list