diff options
author | Mario Corchero <mcorcherojim@bloomberg.net> | 2019-12-06 14:27:38 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-12-06 14:27:38 (GMT) |
commit | b64334cb93d0ddbb551c8cd712942bab2fc72772 (patch) | |
tree | 131741a192a23a07dcd4d7f45aa2a7bd95746238 | |
parent | efefe25443c56988841ab96cdac01352123ba268 (diff) | |
download | cpython-b64334cb93d0ddbb551c8cd712942bab2fc72772.zip cpython-b64334cb93d0ddbb551c8cd712942bab2fc72772.tar.gz cpython-b64334cb93d0ddbb551c8cd712942bab2fc72772.tar.bz2 |
bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py (GH-13135)
Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute.
https://bugs.python.org/issue36820
Automerge-Triggered-By: @pablogsal
-rw-r--r-- | Lib/codeop.py | 11 | ||||
-rw-r--r-- | Lib/ctypes/macholib/dyld.py | 2 | ||||
-rwxr-xr-x | Lib/socket.py | 6 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-05-06-15-34-17.bpo-36820.Eh5mIB.rst | 3 |
4 files changed, 17 insertions, 5 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py index fc7e1e7..082285f 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -93,10 +93,13 @@ def _maybe_compile(compiler, source, filename, symbol): except SyntaxError as e: err2 = e - if code: - return code - if not code1 and repr(err1) == repr(err2): - raise err1 + try: + if code: + return code + if not code1 and repr(err1) == repr(err2): + raise err1 + finally: + err1 = err2 = None def _compile(source, filename, symbol): return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT) diff --git a/Lib/ctypes/macholib/dyld.py b/Lib/ctypes/macholib/dyld.py index c158e67..9d86b05 100644 --- a/Lib/ctypes/macholib/dyld.py +++ b/Lib/ctypes/macholib/dyld.py @@ -149,6 +149,8 @@ def framework_find(fn, executable_path=None, env=None): return dyld_find(fn, executable_path=executable_path, env=env) except ValueError: raise error + finally: + error = None def test_dyld_find(): env = {} diff --git a/Lib/socket.py b/Lib/socket.py index 84a5dcb..374f112 100755 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -839,7 +839,11 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, sock.close() if err is not None: - raise err + try: + raise err + finally: + # Break explicitly a reference cycle + err = None else: raise error("getaddrinfo returns an empty list") diff --git a/Misc/NEWS.d/next/Library/2019-05-06-15-34-17.bpo-36820.Eh5mIB.rst b/Misc/NEWS.d/next/Library/2019-05-06-15-34-17.bpo-36820.Eh5mIB.rst new file mode 100644 index 0000000..82f6635 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-05-06-15-34-17.bpo-36820.Eh5mIB.rst @@ -0,0 +1,3 @@ +Break cycle generated when saving an exception in socket.py, codeop.py and +dyld.py as they keep alive not only the exception but user objects through +the ``__traceback__`` attribute. Patch by Mario Corchero. |