From 10bb21e4f964ee35004efbf75ea9ae5c5873af28 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 14 Apr 2013 11:45:16 +0200 Subject: [PATCH] Fix refcount leak in the reference counting example section (!). --- Doc/c-api/intro.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index c3a9ed633bd5..6414277c849f 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -255,8 +255,10 @@ sets all items of a list (actually, any mutable sequence) to a given item:: PyObject *index = PyInt_FromLong(i); if (!index) return -1; - if (PyObject_SetItem(target, index, item) < 0) + if (PyObject_SetItem(target, index, item) < 0) { + Py_DECREF(index); return -1; + } Py_DECREF(index); } return 0; -- 2.47.3