gh-145376: Fix various reference leaks in Objects/ and Modules/ (#145… · python/cpython@886bc6e · GitHub
Skip to content

Commit 886bc6e

Browse files
gh-145376: Fix various reference leaks in Objects/ and Modules/ (#145385)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 8060aa5 commit 886bc6e

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

Modules/itertoolsmodule.c

Lines changed: 14 additions & 11 deletions

Objects/enumobject.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,16 @@ enum_traverse(PyObject *op, visitproc visit, void *arg)
178178
static inline PyObject *
179179
increment_longindex_lock_held(enumobject *en)
180180
{
181-
PyObject *next_index = en->en_longindex;
182-
if (next_index == NULL) {
183-
next_index = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
184-
if (next_index == NULL) {
181+
if (en->en_longindex == NULL) {
182+
en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
183+
if (en->en_longindex == NULL) {
185184
return NULL;
186185
}
187186
}
188-
assert(next_index != NULL);
187+
assert(en->en_longindex != NULL);
188+
// We hold one reference to "next_index" (a.k.a. the old value of
189+
// en->en_longindex); we'll either return it or keep it in en->en_longindex
190+
PyObject *next_index = en->en_longindex;
189191
PyObject *stepped_up = PyNumber_Add(next_index, en->one);
190192
if (stepped_up == NULL) {
191193
return NULL;

Objects/listobject.c

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)