diff options
author | Colin Watson <cjwatson@canonical.com> | 2021-05-14 02:07:01 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@canonical.com> | 2021-05-14 02:07:01 +0100 |
commit | 034f713d70828c6642194ae80b8d194dc83ca66e (patch) | |
tree | 6ca58addb3cff1b2937d1be87f07c24fcdb463f5 | |
parent | 6f01c1248a284f3abedb33cc38622bbd4319372c (diff) | |
download | zope-pagetemplate-034f713d70828c6642194ae80b8d194dc83ca66e.tar.gz |
Avoid traceback reference cycle in PageTemplate._cook
In Python 3, exceptions have a ``__traceback__`` attribute containing
their associated traceback. Storing an exception in a local variable of
a frame present in that traceback thus creates a reference cycle. Avoid
this by explicitly deleting the exception value when we're finished with
it.
-rw-r--r-- | CHANGES.rst | 2 | ||||
-rw-r--r-- | src/zope/pagetemplate/pagetemplate.py | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 31b0e36..169dfda 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ 4.6.0 (unreleased) ================== -- Nothing changed yet. +- Avoid traceback reference cycle in ``PageTemplate._cook``. 4.5.0 (2020-02-10) diff --git a/src/zope/pagetemplate/pagetemplate.py b/src/zope/pagetemplate/pagetemplate.py index 81b2c8b..78d4d50 100644 --- a/src/zope/pagetemplate/pagetemplate.py +++ b/src/zope/pagetemplate/pagetemplate.py @@ -230,10 +230,13 @@ class PageTemplate(object): source_file, self._text, pt_engine, self.content_type) except: etype, e = sys.exc_info()[:2] - self._v_errors = [ - "Compilation failed", - "%s.%s: %s" % (etype.__module__, etype.__name__, e) - ] + try: + self._v_errors = [ + "Compilation failed", + "%s.%s: %s" % (etype.__module__, etype.__name__, e) + ] + finally: + del e self._v_cooked = 1 |