[3.12] gh-115874: Don't use module state in teedataobject tp_dealloc (GH-116204) (#116955)

(cherry picked from commit e2fcaf19d3)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
This commit is contained in:
Miss Islington (bot) 2024-03-18 13:40:34 +01:00 committed by GitHub
parent 25243b1461
commit 1c0c6c91af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View file

@ -1,7 +1,7 @@
import doctest
import unittest
from test import support
from test.support import threading_helper
from test.support import threading_helper, script_helper
from itertools import *
import weakref
from decimal import Decimal
@ -1695,6 +1695,14 @@ class TestBasicOps(unittest.TestCase):
self.pickletest(proto, a, compare=ans)
self.pickletest(proto, b, compare=ans)
def test_tee_dealloc_segfault(self):
# gh-115874: segfaults when accessing module state in tp_dealloc.
script = (
"import typing, copyreg, itertools; "
"copyreg.buggy_tee = itertools.tee(())"
)
script_helper.assert_python_ok("-c", script)
# Issue 13454: Crash when deleting backward iterator from tee()
def test_tee_del_backward(self):
forward, backward = tee(repeat(None, 20000000))