mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-139748: fix leaks in AC error paths when using unicode FS-b… (#139789)
* [3.14] gh-139748: fix leaks in AC error paths when using unicode FS-based converters (GH-139765)
(cherry picked from commit b04a57deef)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
077652b44f
commit
90cd009209
14 changed files with 88 additions and 46 deletions
|
|
@ -651,6 +651,21 @@ def test_compile_filename(self):
|
|||
compile('pass', filename, 'exec')
|
||||
self.assertRaises(TypeError, compile, 'pass', list(b'file.py'), 'exec')
|
||||
|
||||
def test_compile_filename_refleak(self):
|
||||
# Regression tests for reference leak in PyUnicode_FSDecoder.
|
||||
# See https://github.com/python/cpython/issues/139748.
|
||||
mortal_str = 'this is a mortal string'
|
||||
# check error path when 'mode' AC conversion failed
|
||||
self.assertRaises(TypeError, compile, b'', mortal_str, mode=1234)
|
||||
# check error path when 'optimize' AC conversion failed
|
||||
self.assertRaises(OverflowError, compile, b'', mortal_str,
|
||||
'exec', optimize=1 << 1000)
|
||||
# check error path when 'dont_inherit' AC conversion failed
|
||||
class EvilBool:
|
||||
def __bool__(self): raise ValueError
|
||||
self.assertRaises(ValueError, compile, b'', mortal_str,
|
||||
'exec', dont_inherit=EvilBool())
|
||||
|
||||
@support.cpython_only
|
||||
def test_same_filename_used(self):
|
||||
s = """def f(): pass\ndef g(): pass"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue