Commit e5fa0565 authored by Jim Fulton's avatar Jim Fulton

Fixed a memory leak!

You must *never* assign exc_info() (or sys.exc_info()[2] or
sys.exc_traceback) to a variable unless you also unassign it in a
finally or you'll generate a circular reference in the stack causing
all kinds of interesting things to get leaked.
parent 60bb6ed9
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
import string, sys, traceback import string, sys, traceback
from cStringIO import StringIO from cStringIO import StringIO
from DT_Util import parse_params, render_blocks, namespace, InstanceDict from DT_Util import parse_params, render_blocks, namespace, InstanceDict
from DT_Return import DTReturn
class Try: class Try:
"""Zope DTML Exception handling """Zope DTML Exception handling
...@@ -143,15 +144,17 @@ class Try: ...@@ -143,15 +144,17 @@ class Try:
# first we try to render the first block # first we try to render the first block
try: try:
return render_blocks(self.section, md) return render_blocks(self.section, md)
except DTReturn:
raise # pass through returns
except: except:
# but an error occurs.. save the info. # but an error occurs.. save the info.
einfo = sys.exc_info() t,v = sys.exc_info()[:2]
if type(einfo[0])==type(''): if type(t)==type(''):
errname = einfo[0] errname = t
else: else:
errname = einfo[0].__name__ errname = t.__name__
handler = self.find_handler(einfo[0]) handler = self.find_handler(t)
if handler is None: if handler is None:
# we didn't find a handler, so reraise the error # we didn't find a handler, so reraise the error
...@@ -162,7 +165,7 @@ class Try: ...@@ -162,7 +165,7 @@ class Try:
f=StringIO() f=StringIO()
traceback.print_exc(100,f) traceback.print_exc(100,f)
error_tb=f.getvalue() error_tb=f.getvalue()
ns = namespace(self, error_type=errname, error_value=einfo[1], ns = namespace(self, error_type=errname, error_value=v,
error_tb=error_tb)[0] error_tb=error_tb)[0]
md._push(InstanceDict(ns,md)) md._push(InstanceDict(ns,md))
return render_blocks(handler, md) return render_blocks(handler, md)
...@@ -188,4 +191,4 @@ class Try: ...@@ -188,4 +191,4 @@ class Try:
return 1 return 1
return None return None
__call__ = render __call__ = render
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment