Skip to content

Commit 192fc9f

Browse files
review: update Modules/_collectionsmodule.c
1 parent 9d01cc7 commit 192fc9f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Modules/_collectionsmodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,6 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
25482548
/*[clinic end generated code: output=7e0c1789636b3d8f input=e79fad04534a0b45]*/
25492549
{
25502550
PyObject *it, *oldval;
2551-
PyObject *newval = NULL;
25522551
PyObject *key = NULL;
25532552
PyObject *bound_get = NULL;
25542553
PyObject *mapping_get;
@@ -2597,6 +2596,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
25972596

25982597
int found;
25992598
int cs_err = 0;
2599+
PyObject *newval = NULL;
26002600
Py_BEGIN_CRITICAL_SECTION(mapping);
26012601
found = _PyDict_GetItemRef_KnownHash_LockHeld(
26022602
(PyDictObject *)mapping, key, hash, &oldval);
@@ -2641,6 +2641,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
26412641
oldval = PyObject_CallFunctionObjArgs(bound_get, key, zero, NULL);
26422642
if (oldval == NULL)
26432643
break;
2644+
PyObject *newval;
26442645
if (oldval == zero) {
26452646
newval = Py_NewRef(one);
26462647
} else {
@@ -2649,9 +2650,10 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
26492650
Py_DECREF(oldval);
26502651
if (newval == NULL)
26512652
break;
2652-
if (PyObject_SetItem(mapping, key, newval) < 0)
2653+
int status = PyObject_SetItem(mapping, key, newval);
2654+
Py_DECREF(newval);
2655+
if (status < 0)
26532656
break;
2654-
Py_CLEAR(newval);
26552657
Py_DECREF(key);
26562658
}
26572659
}
@@ -2661,7 +2663,6 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
26612663
Py_XDECREF(mapping_setitem);
26622664
Py_DECREF(it);
26632665
Py_XDECREF(key);
2664-
Py_XDECREF(newval);
26652666
Py_XDECREF(bound_get);
26662667
if (PyErr_Occurred())
26672668
return NULL;

0 commit comments

Comments
 (0)