https://github.com/python/cpython/commit/587b7a5b315a971ecd376184a1f1cbecaa9e6f21
commit: 587b7a5b315a971ecd376184a1f1cbecaa9e6f21
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-04T22:07:31Z
summary:

gh-158585: Fix refleak in _testcapi.bytes_resize() (#158806)

files:
M Modules/_testcapi/bytes.c

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);
 }
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to