-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize/Finalize Python multiple time and import _ctypes each time lead to a memory corruption #116467
Comments
The regression was introduced by commit ea2c001:
|
I can still reproduce the bug with this code. Maybe the problem comes from the |
Python 3.12 and main branches are affected (Python 3.11 and older are not affected). I can reproduce the issue on Linux with the script: import subprocess
program = r"Programs/_testembed"
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() |
The error occurs when the
At the first
|
I propose removing StgDict, with this big patch: #116458. |
Using @vstinner's repro from #116467 (comment), I can confirm that #116458 resolves the issue 🚀 🎉 IOW, let's get on with reviewing that big patch 😄 |
#116458 does resolve use-after-free of almost all ctypes-related interned strings. Also, please consider making the following string pointers cpython/Tools/c-analyzer/cpython/globals-to-fix.tsv Lines 415 to 420 in bb66600
|
IMO it's ok to not fix the issue in Python 3.12. Apparently, I was the only one who noticed, so it's not a big deal. I close the issue. Thanks for the fix @encukou! |
Example on Windows:
Output:
The text was updated successfully, but these errors were encountered: