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.
This commit is contained in:
Victor Stinner 2023-08-23 07:26:01 +02:00 committed by GitHub
parent 9173b2bbe1
commit 64f9935035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View 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