◐ Shell
clean mode source ↗

gh-146102:Fix cross-interpreter NotShareableError ref handling by lpyu001 · Pull Request #151578 · python/cpython

This fixes two ownership issues:

  • _ensure_notshareableerror() now returns immediately when the current raised exception is already a NotShareableError. The function had restored ctx to the thread state but then continued using it, even though ownership had been handed back.
  • _PyXI_UnwrapNotShareableError() now decrefs the exception taken from the thread state if _PyXI_InitFailure() fails, avoiding a leaked exception reference on that error path.

The _pop_preserved() shadowed-variable leak is already fixed on this branch, so this PR does not touch it.

glist:https://gist.github.com/devdanzin/a56b8cb579b1950b4206e8a42d6be650