From: Victor Stinner Date: Wed, 23 Aug 2023 05:26:01 +0000 (+0200) Subject: gh-108342: Break ref cycle in SSLSocket._create() exc (#108344) X-Git-Tag: v3.13.0a1~838 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=64f99350351bc46e016b2286f36ba7cd669b79e3;p=thirdparty%2FPython%2Fcpython.git gh-108342: Break ref cycle in SSLSocket._create() exc (#108344) 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. --- diff --git a/Lib/ssl.py b/Lib/ssl.py index ff363c75e7df..c4c5a4ca894e 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -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