summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-28 22:56:58 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-28 22:56:58 (GMT)
commit07e20ef50b52d2359213bc5d91f809a76cfd1524 (patch)
tree74803fa7efe3959104b0d9760e4cff172e5c3919 /Lib/test
parent1842d0c4d88fffb5bea53b410acb77796b66bc8b (diff)
downloadcpython-07e20ef50b52d2359213bc5d91f809a76cfd1524.zip
cpython-07e20ef50b52d2359213bc5d91f809a76cfd1524.tar.gz
cpython-07e20ef50b52d2359213bc5d91f809a76cfd1524.tar.bz2
Issue #5437: A preallocated MemoryError instance should not hold traceback
data (including local variables caught in the stack trace) alive infinitely.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exceptions.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index e2824b2..2cbd972 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -721,6 +721,45 @@ class ExceptionTests(unittest.TestCase):
self.assertEqual(error5.a, 1)
self.assertEqual(error5.__doc__, "")
+ def test_memory_error_cleanup(self):
+ # Issue #5437: preallocated MemoryError instances should not keep
+ # traceback objects alive.
+ from _testcapi import raise_memoryerror
+ class C:
+ pass
+ wr = None
+ def inner():
+ nonlocal wr
+ c = C()
+ wr = weakref.ref(c)
+ raise_memoryerror()
+ # We cannot use assertRaises since it manually deletes the traceback
+ try:
+ inner()
+ except MemoryError as e:
+ self.assertNotEqual(wr(), None)
+ else:
+ self.fail("MemoryError not raised")
+ self.assertEqual(wr(), None)
+
+ def test_recursion_error_cleanup(self):
+ # Same test as above, but with "recursion exceeded" errors
+ class C:
+ pass
+ wr = None
+ def inner():
+ nonlocal wr
+ c = C()
+ wr = weakref.ref(c)
+ inner()
+ # We cannot use assertRaises since it manually deletes the traceback
+ try:
+ inner()
+ except RuntimeError as e:
+ self.assertNotEqual(wr(), None)
+ else:
+ self.fail("RuntimeError not raised")
+ self.assertEqual(wr(), None)
def test_main():
run_unittest(ExceptionTests)