From a923bd04c15e11dd296e78522e474df81ddf81e3 Mon Sep 17 00:00:00 2001 From: An Long Date: Tue, 14 Jul 2026 00:00:52 +0900 Subject: [PATCH 1/2] gh-153664: Fix reference leaks in cross-interpreter NotShareableError handling --- .../2026-07-13-23-59-45.gh-issue-153664.MQYdit.rst | 2 ++ Python/crossinterp_data_lookup.h | 1 + Python/crossinterp_exceptions.h | 1 + 3 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-07-13-23-59-45.gh-issue-153664.MQYdit.rst 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..3fcbb2798f283e --- /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 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 { From 7407ba0e6153f7cbd92cbb02a8a030dc9b3ce4c9 Mon Sep 17 00:00:00 2001 From: An Long Date: Tue, 14 Jul 2026 00:14:16 +0900 Subject: [PATCH 2/2] gh-153664: Update news entry wording --- .../2026-07-13-23-59-45.gh-issue-153664.MQYdit.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 3fcbb2798f283e..db758c4d2c21d2 100644 --- 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 @@ -1,2 +1,2 @@ -Fix potential reference leaks in cross-interpreter ``NotShareableError`` -error handling. +Fix potential use-after-free and reference leaks in cross-interpreter +``NotShareableError`` error handling.