diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-13-23-59-45.gh-issue-153664.MQYdit.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-13-23-59-45.gh-issue-153664.MQYdit.rst new file mode 100644 index 00000000000000..db758c4d2c21d2 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-13-23-59-45.gh-issue-153664.MQYdit.rst @@ -0,0 +1,2 @@ +Fix potential use-after-free and reference leaks in cross-interpreter +``NotShareableError`` error handling. diff --git a/Python/crossinterp_data_lookup.h b/Python/crossinterp_data_lookup.h index 54422ad2335cb6..62fe3ff44660b7 100644 --- a/Python/crossinterp_data_lookup.h +++ b/Python/crossinterp_data_lookup.h @@ -100,6 +100,7 @@ _PyXI_UnwrapNotShareableError(PyThreadState * tstate, _PyXI_failure *failure) if (failure != NULL) { _PyXI_errcode code = _PyXI_ERR_NOT_SHAREABLE; if (_PyXI_InitFailure(failure, code, exc) < 0) { + Py_DECREF(exc); return -1; } } diff --git a/Python/crossinterp_exceptions.h b/Python/crossinterp_exceptions.h index 98411adc5eb3f6..0d144ffdaf4f5b 100644 --- a/Python/crossinterp_exceptions.h +++ b/Python/crossinterp_exceptions.h @@ -83,6 +83,7 @@ _ensure_notshareableerror(PyThreadState *tstate, // A NotShareableError instance is already set. assert(cause == NULL); _PyErr_SetRaisedException(tstate, ctx); + return; } } else {