bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)
if it is called with a sequence or set, but not list or tuple.
(cherry picked from commit f572cbf1faab33d9afbbe3e95738ed6fbe6e48e6)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index e7a60db..6e5ef09 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -43,8 +43,14 @@ def get_tk_patchlevel():
class TkinterTest(unittest.TestCase):
def testFlattenLen(self):
- # flatten(<object with no length>)
+ # Object without length.
self.assertRaises(TypeError, _tkinter._flatten, True)
+ # Object with length, but not sequence.
+ self.assertRaises(TypeError, _tkinter._flatten, {})
+ # Sequence or set, but not tuple or list.
+ # (issue44608: there were leaks in the following cases)
+ self.assertRaises(TypeError, _tkinter._flatten, 'string')
+ self.assertRaises(TypeError, _tkinter._flatten, {'set'})
class TclTest(unittest.TestCase):