Skip to content

Commit 2e94a66

Browse files
authored
gh-116099: Fix refcounting bug in _queueobj_shared() (gh-116164)
This code decrefs `qidobj` twice in some paths. Since `qidobj` isn't used after the first `Py_DECREF()`, remove the others, and replace the `Py_DECREF()` with `Py_CLEAR()` to make it clear that the variable is dead. With this fix, `python -mtest test_interpreters -R 3:3 -mtest_queues` no longer fails with `_Py_NegativeRefcount: Assertion failed: object has negative ref count`.
1 parent d7ddd90 commit 2e94a66

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Modules/_xxinterpqueuesmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,20 +1189,18 @@ _queueobj_shared(PyThreadState *tstate, PyObject *queueobj,
11891189
.label = "queue ID",
11901190
};
11911191
int res = idarg_int64_converter(qidobj, &converted);
1192-
Py_DECREF(qidobj);
1192+
Py_CLEAR(qidobj);
11931193
if (!res) {
11941194
assert(PyErr_Occurred());
11951195
return -1;
11961196
}
11971197

11981198
void *raw = _queueid_xid_new(converted.id);
11991199
if (raw == NULL) {
1200-
Py_DECREF(qidobj);
12011200
return -1;
12021201
}
12031202
_PyCrossInterpreterData_Init(data, tstate->interp, raw, NULL,
12041203
_queueobj_from_xid);
1205-
Py_DECREF(qidobj);
12061204
_PyCrossInterpreterData_SET_FREE(data, _queueid_xid_free);
12071205
return 0;
12081206
}

0 commit comments

Comments
 (0)