diff --git a/Modules/_testcapi/bytes.c b/Modules/_testcapi/bytes.c index e9ed765850a907..605df203d6fc9a 100644 --- a/Modules/_testcapi/bytes.c +++ b/Modules/_testcapi/bytes.c @@ -42,6 +42,7 @@ bytes_resize(PyObject *Py_UNUSED(module), PyObject *args, PyObject *kwargs) if (compute_hash) { if (PyObject_Hash(obj) == -1) { + Py_DECREF(obj); return NULL; } } @@ -56,7 +57,7 @@ bytes_resize(PyObject *Py_UNUSED(module), PyObject *args, PyObject *kwargs) } Py_ssize_t refcnt = Py_REFCNT(obj); - return Py_BuildValue("Onp", obj, refcnt, obj != old_obj); + return Py_BuildValue("Nnp", obj, refcnt, obj != old_obj); }