gh-130519: Fix crash in QSBR when destructor reenters QSBR (gh-130553)

The `free_work_item()` function in QSBR may call arbitrary code via
Python object destructors, which may reenter the QSBR code. Reorder
the processing of work items to be robust to reentrancy.

Also fix the TODO for the out of memory situation.
This commit is contained in:
Sam Gross 2025-02-26 14:55:15 -05:00 committed by GitHub
parent 5c8e8704c3
commit 45bc120d45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 10 deletions

View file

@ -1995,6 +1995,13 @@ is_static_immortal(PyObject *self, PyObject *op)
Py_RETURN_FALSE;
}
static PyObject *
incref_decref_delayed(PyObject *self, PyObject *op)
{
_PyObject_XDecRefDelayed(Py_NewRef(op));
Py_RETURN_NONE;
}
static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@ -2089,6 +2096,7 @@ static PyMethodDef module_functions[] = {
{"has_deferred_refcount", has_deferred_refcount, METH_O},
{"get_tracked_heap_size", get_tracked_heap_size, METH_NOARGS},
{"is_static_immortal", is_static_immortal, METH_O},
{"incref_decref_delayed", incref_decref_delayed, METH_O},
{NULL, NULL} /* sentinel */
};