Skip to content

Commit

Permalink
pythongh-116099: Fix refcounting bug in _queueobj_shared() (pythong…
Browse files Browse the repository at this point in the history
…h-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`.
  • Loading branch information
swtaarrs authored and woodruffw committed Mar 4, 2024
1 parent 625d530 commit 1faacdc
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions Modules/_xxinterpqueuesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,20 +1189,18 @@ _queueobj_shared(PyThreadState *tstate, PyObject *queueobj,
.label = "queue ID",
};
int res = idarg_int64_converter(qidobj, &converted);
Py_DECREF(qidobj);
Py_CLEAR(qidobj);
if (!res) {
assert(PyErr_Occurred());
return -1;
}

void *raw = _queueid_xid_new(converted.id);
if (raw == NULL) {
Py_DECREF(qidobj);
return -1;
}
_PyCrossInterpreterData_Init(data, tstate->interp, raw, NULL,
_queueobj_from_xid);
Py_DECREF(qidobj);
_PyCrossInterpreterData_SET_FREE(data, _queueid_xid_free);
return 0;
}
Expand Down

0 comments on commit 1faacdc

Please sign in to comment.