Commit 0193a629 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix memleak in exception handling code (#162)

parent 226a8ac6
...@@ -3883,6 +3883,7 @@ class TryExceptStatNode(StatNode): ...@@ -3883,6 +3883,7 @@ class TryExceptStatNode(StatNode):
except_end_label = code.new_label('exception_handled') except_end_label = code.new_label('exception_handled')
except_error_label = code.new_label('except_error') except_error_label = code.new_label('except_error')
except_return_label = code.new_label('except_return') except_return_label = code.new_label('except_return')
try_return_label = code.new_label('try_return')
try_end_label = code.new_label('try') try_end_label = code.new_label('try')
code.putln("{") code.putln("{")
...@@ -3892,6 +3893,7 @@ class TryExceptStatNode(StatNode): ...@@ -3892,6 +3893,7 @@ class TryExceptStatNode(StatNode):
', '.join(['&%s' % var for var in Naming.exc_save_vars])) ', '.join(['&%s' % var for var in Naming.exc_save_vars]))
code.putln( code.putln(
"/*try:*/ {") "/*try:*/ {")
code.return_label = try_return_label
self.body.generate_execution_code(code) self.body.generate_execution_code(code)
code.putln( code.putln(
"}") "}")
...@@ -3906,6 +3908,11 @@ class TryExceptStatNode(StatNode): ...@@ -3906,6 +3908,11 @@ class TryExceptStatNode(StatNode):
for var in Naming.exc_save_vars: for var in Naming.exc_save_vars:
code.put_xdecref_clear(var, py_object_type) code.put_xdecref_clear(var, py_object_type)
code.put_goto(try_end_label) code.put_goto(try_end_label)
if code.label_used(try_return_label):
code.put_label(try_return_label)
for var in Naming.exc_save_vars:
code.put_xdecref_clear(var, py_object_type)
code.put_goto(old_return_label)
code.put_label(our_error_label) code.put_label(our_error_label)
code.put_var_xdecrefs_clear(self.cleanup_list) code.put_var_xdecrefs_clear(self.cleanup_list)
for except_clause in self.except_clauses: for except_clause in self.except_clauses:
......
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