Skip to content

Commit af4ec4c

Browse files
committed
gh-158585: Fix refleak in _testcapi.bytes_resize()
1 parent 9d22a53 commit af4ec4c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎Modules/_testcapi/bytes.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ bytes_resize(PyObject *Py_UNUSED(module), PyObject *args, PyObject *kwargs)
4242

4343
if (compute_hash) {
4444
if (PyObject_Hash(obj) == -1) {
45+
Py_DECREF(obj);
4546
return NULL;
4647
}
4748
}
@@ -56,7 +57,7 @@ bytes_resize(PyObject *Py_UNUSED(module), PyObject *args, PyObject *kwargs)
5657
}
5758

5859
Py_ssize_t refcnt = Py_REFCNT(obj);
59-
return Py_BuildValue("Onp", obj, refcnt, obj != old_obj);
60+
return Py_BuildValue("Nnp", obj, refcnt, obj != old_obj);
6061
}
6162

6263

0 commit comments

Comments
 (0)