]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-111499: Fix PYTHONMALLOCSTATS at Python exit (#120021) (#120023)
authorVictor Stinner <vstinner@python.org>
Tue, 4 Jun 2024 09:58:49 +0000 (11:58 +0200)
committerGitHub <noreply@github.com>
Tue, 4 Jun 2024 09:58:49 +0000 (09:58 +0000)
gh-111499: Fix PYTHONMALLOCSTATS at Python exit (#120021)

Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before
the interpreter is deleted.

(cherry picked from commit 5a1205b641df133932ed4c65b9a4ff5724e89963)

Python/pylifecycle.c

index a0130fde15d574e7bb339df679b05751ef6f0903..2c36527a8754d1341a59c629d7a5f3215abfc94f 100644 (file)
@@ -1969,6 +1969,13 @@ Py_FinalizeEx(void)
     // XXX Ensure finalizer errors are handled properly.
 
     finalize_interp_clear(tstate);
+
+#ifdef WITH_PYMALLOC
+    if (malloc_stats) {
+        _PyObject_DebugMallocStats(stderr);
+    }
+#endif
+
     finalize_interp_delete(tstate->interp);
 
 #ifdef Py_REF_DEBUG
@@ -1994,11 +2001,6 @@ Py_FinalizeEx(void)
         fclose(dump_refs_fp);
     }
 #endif /* Py_TRACE_REFS */
-#ifdef WITH_PYMALLOC
-    if (malloc_stats) {
-        _PyObject_DebugMallocStats(stderr);
-    }
-#endif
 
     call_ll_exitfuncs(runtime);