Skip to content

Initialize/Finalize Python multiple time and import _ctypes each time lead to a memory corruption #116467

@vstinner

Description

@vstinner

Example on Windows:

import subprocess program = r"PCbuild\amd64\_testembed_d.exe" cmd = [program, "test_repeated_init_exec", "import _ctypes"] for i in range(1, 11): print(f" == Process #{i} ===") proc = subprocess.run(cmd) exitcode = proc.returncode print(f"=> exitcode {exitcode}") if exitcode: break print()

Output:

vstinner@WIN C:\victor\python\main>python bug.py Running Debug|x64 interpreter... == Process #1 === --- Loop #1 --- --- Loop #2 --- --- Loop #3 --- --- Loop #4 --- => exitcode 0 == Process #2 === --- Loop #1 --- --- Loop #2 --- Assertion failed: PyUnicode_CheckExact(ep->me_key), file C:\victor\python\main\Objects\dictobject.c, line 922 => exitcode 3 

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestopic-ctypestype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions