Browse Source

bpo-44608: Fix memory leak in _tkinter._flatten() (GH-27107)

if it is called with a sequence or set, but not list or tuple.
pull/27139/head
Serhiy Storchaka 5 years ago
committed by GitHub
parent
commit
f572cbf1fa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      Lib/test/test_tcl.py
  2. 2
      Misc/NEWS.d/next/Library/2021-07-13-09-01-33.bpo-44608.R3IcM1.rst
  3. 4
      Modules/_tkinter.c

8
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):

2
Misc/NEWS.d/next/Library/2021-07-13-09-01-33.bpo-44608.R3IcM1.rst

@ -0,0 +1,2 @@
Fix memory leak in :func:`_tkinter._flatten` if it is called with a sequence
or set, but not list or tuple.

4
Modules/_tkinter.c

@ -3197,8 +3197,10 @@ _tkinter__flatten(PyObject *module, PyObject *item)
context.size = 0;
if (!_flatten1(&context, item,0))
if (!_flatten1(&context, item, 0)) {
Py_XDECREF(context.tuple);
return NULL;
}
if (_PyTuple_Resize(&context.tuple, context.size))
return NULL;

Loading…
Cancel
Save