[3.14] gh-144766: Fix a crash in fork child process when perf support is enabled. (GH-144795) (#144816)

This commit is contained in:
Miss Islington (bot) 2026-02-14 13:09:00 +01:00 committed by GitHub
parent c7ceb75ada
commit 77b71ac793
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 0 deletions

View file

@ -620,6 +620,12 @@ _PyPerfTrampoline_AfterFork_Child(void)
int was_active = _PyIsPerfTrampolineActive();
_PyPerfTrampoline_Fini();
if (was_active) {
// After fork, Fini may leave the old code watcher registered
// if trampolined code objects from the parent still exist
// (trampoline_refcount > 0). Clear it unconditionally before
// Init registers a new one, to prevent two watchers sharing
// the same globals and double-decrementing trampoline_refcount.
perf_trampoline_reset_state();
_PyPerfTrampoline_Init(1);
}
}