[3.13] gh-140939: Fix memory leak in _PyBytes_FormatEx error path (GH-140957) (#141155)

(cherry picked from commit d6c89a2df2)
This commit is contained in:
Stan Ulbrych 2025-11-06 16:16:43 +00:00 committed by GitHub
parent 908695b5c7
commit f1a93727c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View file

@ -769,6 +769,13 @@ def __int__(self):
with self.assertRaisesRegex(TypeError, msg):
operator.mod(format_bytes, value)
def test_memory_leak_gh_140939(self):
# gh-140939: MemoryError is raised without leaking
_testcapi = import_helper.import_module('_testcapi')
with self.assertRaises(MemoryError):
b = self.type2test(b'%*b')
b % (_testcapi.PY_SSIZE_T_MAX, b'abc')
def test_imod(self):
b = self.type2test(b'hello, %b!')
orig = b