/* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */
- _PyTraceMalloc_Stop();
+ _PyTraceMalloc_Fini();
/* Finalize any remaining import state */
// XXX Move these up to where finalize_modules() is currently.
finalize_interp_clear(tstate);
- _PyTraceMalloc_Fini();
#ifdef Py_TRACE_REFS
/* Display addresses (& refcnts) of all objects still alive.
size_t size)
{
PyGILState_STATE gil_state = PyGILState_Ensure();
- int result;
-
- // gh-129185: Check before TABLES_LOCK() to support calls after
- // _PyTraceMalloc_Fini().
- if (!tracemalloc_config.tracing) {
- result = -2;
- goto done;
- }
-
TABLES_LOCK();
+ int result;
if (tracemalloc_config.tracing) {
result = tracemalloc_add_trace_unlocked(domain, ptr, size);
}
}
TABLES_UNLOCK();
-done:
PyGILState_Release(gil_state);
-
return result;
}
int
PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
{
- // Need the GIL to prevent races on the first 'tracing' test
- PyGILState_STATE gil_state = PyGILState_Ensure();
- int result;
-
- // gh-129185: Check before TABLES_LOCK() to support calls after
- // _PyTraceMalloc_Fini()
- if (!tracemalloc_config.tracing) {
- result = -2;
- goto done;
- }
-
TABLES_LOCK();
+ int result;
if (tracemalloc_config.tracing) {
tracemalloc_remove_trace_unlocked(domain, ptr);
result = 0;
}
TABLES_UNLOCK();
-done:
- PyGILState_Release(gil_state);
return result;
}