]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-108342: Break ref cycle in SSLSocket._create() exc (GH-108344) (#108349)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 23 Aug 2023 10:10:04 +0000 (03:10 -0700)
committerGitHub <noreply@github.com>
Wed, 23 Aug 2023 10:10:04 +0000 (12:10 +0200)
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@python.org>
Lib/ssl.py

index ced87d406995c154b84899650438bd3302f89a7c..48d229f810af28bb56da0ed902e6e5e4a5e351db 100644 (file)
@@ -1083,7 +1083,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