summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-09 22:31:10 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-09 22:31:10 +0200
commit4673eb667602461ff261b546216c183c1f84e9d7 (patch)
tree19f868ca6a45bb818a7722b4fac1ff8d81b76dad
parentf37987671466ff9d621a71d5005cb5a28e3c841f (diff)
downloadcpython-4673eb667602461ff261b546216c183c1f84e9d7.tar.gz
Issue #25582: Fixed 100 MB memory leak in test_ctypes.
-rw-r--r--Lib/ctypes/test/test_pointers.py12
-rw-r--r--Lib/ctypes/test/test_win32.py4
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py
index e24a520dbe..6eea58fb43 100644
--- a/Lib/ctypes/test/test_pointers.py
+++ b/Lib/ctypes/test/test_pointers.py
@@ -192,9 +192,19 @@ class PointersTestCase(unittest.TestCase):
LargeNamedType = type('T' * 2 ** 25, (Structure,), {})
self.assertTrue(POINTER(LargeNamedType))
+ # to not leak references, we must clean _pointer_type_cache
+ from ctypes import _pointer_type_cache
+ del _pointer_type_cache[LargeNamedType]
+
def test_pointer_type_str_name(self):
large_string = 'T' * 2 ** 25
- self.assertTrue(POINTER(large_string))
+ P = POINTER(large_string)
+ self.assertTrue(P)
+
+ # to not leak references, we must clean _pointer_type_cache
+ from ctypes import _pointer_type_cache
+ del _pointer_type_cache[id(P)]
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py
index 5867b05929..da1624015e 100644
--- a/Lib/ctypes/test/test_win32.py
+++ b/Lib/ctypes/test/test_win32.py
@@ -135,5 +135,9 @@ class Structures(unittest.TestCase):
self.assertEqual(ret.top, top.value)
self.assertEqual(ret.bottom, bottom.value)
+ # to not leak references, we must clean _pointer_type_cache
+ from ctypes import _pointer_type_cache
+ del _pointer_type_cache[RECT]
+
if __name__ == '__main__':
unittest.main()