[Python-checkins] [3.12] gh-108342: Break ref cycle in SSLSocket._create() exc (GH-108344) (#108348)

ambv webhook-mailer at python.org
Wed Aug 23 06:09:58 EDT 2023


https://github.com/python/cpython/commit/61dbf46ae3df9d772bfd91b89ab61baeff97a12d
commit: 61dbf46ae3df9d772bfd91b89ab61baeff97a12d
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2023-08-23T12:09:55+02:00
summary:

[3.12] gh-108342: Break ref cycle in SSLSocket._create() exc (GH-108344) (#108348)

Explicitly break a reference cycle when SSLSocket._create() raises an
exception. Clear the variable storing the exception, since the
exception traceback contains the variables and so creates a reference
cycle.

This test leak was introduced by the test added for the fix of GH-108310.
(cherry picked from commit 64f99350351bc46e016b2286f36ba7cd669b79e3)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
M Lib/ssl.py

diff --git a/Lib/ssl.py b/Lib/ssl.py
index ff363c75e7dfd..c4c5a4ca894ee 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -1021,7 +1021,11 @@ def _create(cls, sock, server_side=False, do_handshake_on_connect=True,
                     self.close()
                 except OSError:
                     pass
-                raise notconn_pre_handshake_data_error
+                try:
+                    raise notconn_pre_handshake_data_error
+                finally:
+                    # Explicitly break the reference cycle.
+                    notconn_pre_handshake_data_error = None
         else:
             connected = True
 



More information about the Python-checkins mailing list