Skip to content

Commit 4a01fa0

Browse files
committed
Fix refcount leaks in hamt allocation failure paths
1 parent cb3b4b9 commit 4a01fa0

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix two reference count leaks in :mod:`!hamt` on memory allocation failure
2+
paths inside ``hamt_node_bitmap_assoc`` and ``hamt_node_bitmap_without``.
3+
These leaks could occur if ``hamt_node_bitmap_clone`` failed after a
4+
recursive ``assoc``/``without`` call had already produced a new sub-node.

Python/hamt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ hamt_node_bitmap_assoc(PyHamtNode_Bitmap *self,
702702

703703
PyHamtNode_Bitmap *ret = hamt_node_bitmap_clone(self);
704704
if (ret == NULL) {
705+
Py_DECREF(sub_node);
705706
return NULL;
706707
}
707708
Py_SETREF(ret->b_array[val_idx], (PyObject*)sub_node);
@@ -994,6 +995,7 @@ hamt_node_bitmap_without(PyHamtNode_Bitmap *self,
994995

995996
PyHamtNode_Bitmap *clone = hamt_node_bitmap_clone(self);
996997
if (clone == NULL) {
998+
Py_DECREF(sub_node);
997999
return W_ERROR;
9981000
}
9991001

0 commit comments

Comments
 (0)