summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Watson <cjwatson@canonical.com>2021-05-14 02:07:01 +0100
committerColin Watson <cjwatson@canonical.com>2021-05-14 02:07:01 +0100
commit034f713d70828c6642194ae80b8d194dc83ca66e (patch)
tree6ca58addb3cff1b2937d1be87f07c24fcdb463f5 /src
parent6f01c1248a284f3abedb33cc38622bbd4319372c (diff)
downloadzope-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.
Diffstat (limited to 'src')
-rw-r--r--src/zope/pagetemplate/pagetemplate.py11
1 files changed, 7 insertions, 4 deletions
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