You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segmentation fault during interpreter finalization in PyTraceMalloc_Untrack #129185
_PyTraceMalloc_Fini is called before _PyImport_Fini in _Py_Finalize. This can lead to crashes when using tracemalloc if calls to PyTraceMalloc_Untrack are performed during finalization of module (e.g in the destructor of some global variable).
Commit 6b47499 moved the call to TABLES_LOCK before the check tracemalloc_config.tracing so now the issue whether or not tracemalloc is started.
The following extension module reproduces the issue:
Btw, PyModule_AddObject steals a reference, so you might want to incref arr before since you're storing it in a global variable but I don't know whether this would solve the issue. Now, can you actually produce a reproducer that does not depend on numpy so that we can possibly add a regression test?
Activity
picnixz commentedon Jan 22, 2025
Btw,
PyModule_AddObjectsteals a reference, so you might want to increfarrbefore since you're storing it in a global variable but I don't know whether this would solve the issue. Now, can you actually produce a reproducer that does not depend onnumpyso that we can possibly add a regression test?cc @vstinner
pythongh-129185: Fix PyTraceMalloc_Untrack() at Python exit
pythongh-129185: Fix PyTraceMalloc_Untrack() at Python exit
vstinner commentedon Jan 22, 2025
I wrote a different fix with a test: PR gh-129191.
gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191)
pythongh-129185: Fix PyTraceMalloc_Untrack() at Python exit (python#1…
pythongh-129185: Remove internal TRACE_RAW_MALLOC macro
gh-129185: Remove internal TRACE_RAW_MALLOC macro (#129218)
[3.13] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (
vstinner commentedon Jan 23, 2025
Thanks @rostan-t for the bug report and for the initial fix! It's now fixed in 3.13 and main branches, and the 3.12 fix is incoming.
[3.12] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (
pythongh-129185: Use PyMutex in tracemalloc
pythongh-129185: Use PyMutex in tracemalloc
gh-129185: Use PyMutex in tracemalloc (#129246)
pythongh-129185: Simplify PyTraceMalloc_Track()
pythongh-129185: Simplify PyTraceMalloc_Track()
gh-129185: Simplify PyTraceMalloc_Track() (#129256)