[New-bugs-announce] [issue44441] Malformed PyImport_Inittab after re-initialization

kryheb report at bugs.python.org
Thu Jun 17 06:14:12 EDT 2021


New submission from kryheb <krystianheberlein at gmail.com>:

Hi all,

I observed misbehavior trying to embed the Python interpreter into a C app.
It seems that after re-initialization, PyImport_Inittab is malformed and points to the memory freed _PyImport_Fini2.


Steps to reproduce:

1. Append embedded module
2. Initialize Python from config with run_filename
3. Run main with an infinite loop
4. Interrupt script execution with async call
5. Finalize Python
6. Repeat all above

Observed behavior:
The script is executed at first iteration, but re-initialization fails with an error:
"
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1187, in _install_external_importers
ModuleNotFoundError: No module named 'posix'

Error: external importer setup failed
"

Head of modules list at fist run:
------ Modules: ------
#0 'posix'
#1 'errno'
#2 'pwd'
----------------------
and after re-initialization:
------ Modules: ------
#0 'P ''
#1 'errno'
#2 'pwd'
----------------------

An issue discovered on:
Fedora 33
gcc (GCC) 10.3.1 20210422 (Red Hat 10.3.1-1)
python3-devel.x86_64 3.9.5-2.fc33

Issue still exists on the latest main and on the rc 3.10
Source code to reproduce an issue in attachment.

Best regards,
Krystian Heberlein

----------
components: C API, Library (Lib)
files: inittab-bug.c
messages: 395985
nosy: kryheb
priority: normal
severity: normal
status: open
title: Malformed PyImport_Inittab after re-initialization
versions: Python 3.10, Python 3.9
Added file: https://bugs.python.org/file50115/inittab-bug.c

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44441>
_______________________________________


More information about the New-bugs-announce mailing list