]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108342: Break ref cycle in SSLSocket._create() exc (#108344)
authorVictor Stinner <vstinner@python.org>
Wed, 23 Aug 2023 05:26:01 +0000 (07:26 +0200)
committerGitHub <noreply@github.com>
Wed, 23 Aug 2023 05:26:01 +0000 (05:26 +0000)
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 #108310.

Lib/ssl.py

index ff363c75e7dfd804995763218d2f078412f65337..c4c5a4ca894ee578bf0b5d080cd8ff6a5f242ca1 100644 (file)
@@ -1021,7 +1021,11 @@ class SSLSocket(socket):
                     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