From 4a01fa025d796db97c5367a6ba8f53ea27d1f924 Mon Sep 17 00:00:00 2001 From: lipengyu Date: Thu, 21 May 2026 15:49:46 +0800 Subject: [PATCH 1/2] Fix refcount leaks in hamt allocation failure paths --- .../2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst | 4 ++++ Python/hamt.c | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst new file mode 100644 index 00000000000000..2c7e86a7a75fc0 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst @@ -0,0 +1,4 @@ +Fix two reference count leaks in :mod:`!hamt` on memory allocation failure +paths inside ``hamt_node_bitmap_assoc`` and ``hamt_node_bitmap_without``. +These leaks could occur if ``hamt_node_bitmap_clone`` failed after a +recursive ``assoc``/``without`` call had already produced a new sub-node. diff --git a/Python/hamt.c b/Python/hamt.c index e4719e71a5259a..95998ae5062ac7 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -702,6 +702,7 @@ hamt_node_bitmap_assoc(PyHamtNode_Bitmap *self, PyHamtNode_Bitmap *ret = hamt_node_bitmap_clone(self); if (ret == NULL) { + Py_DECREF(sub_node); return NULL; } Py_SETREF(ret->b_array[val_idx], (PyObject*)sub_node); @@ -994,6 +995,7 @@ hamt_node_bitmap_without(PyHamtNode_Bitmap *self, PyHamtNode_Bitmap *clone = hamt_node_bitmap_clone(self); if (clone == NULL) { + Py_DECREF(sub_node); return W_ERROR; } From 1589a15b9209ca5d29ffb62940159bfd2cc8a3dd Mon Sep 17 00:00:00 2001 From: lipengyu Date: Thu, 21 May 2026 17:49:25 +0800 Subject: [PATCH 2/2] delete NEWS --- .../2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst deleted file mode 100644 index 2c7e86a7a75fc0..00000000000000 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-21-15-32-07.gh-issue-150178.2UKr8i.rst +++ /dev/null @@ -1,4 +0,0 @@ -Fix two reference count leaks in :mod:`!hamt` on memory allocation failure -paths inside ``hamt_node_bitmap_assoc`` and ``hamt_node_bitmap_without``. -These leaks could occur if ``hamt_node_bitmap_clone`` failed after a -recursive ``assoc``/``without`` call had already produced a new sub-node.