Skip to content

Commit 250f3e9

Browse files
committed
more paranoid
1 parent 52c7d2b commit 250f3e9

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Python/sysmodule.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,13 +2666,22 @@ sys__clear_type_descriptors(PyObject *module, PyObject *type)
26662666
return NULL;
26672667
}
26682668
PyObject *dict = _PyType_GetDict(typeobj);
2669-
if (PyDict_PopString(dict, "__dict__", NULL) < 0) {
2669+
PyObject *dunder_dict = NULL;
2670+
if (PyDict_PopString(dict, "__dict__", &dunder_dict) < 0) {
26702671
return NULL;
26712672
}
2672-
if (PyDict_PopString(dict, "__weakref__", NULL) < 0) {
2673+
PyObject *dunder_weakref = NULL;
2674+
if (PyDict_PopString(dict, "__weakref__", &dunder_weakref) < 0) {
2675+
PyType_Modified(typeobj);
2676+
Py_XDECREF(dunder_dict);
26732677
return NULL;
26742678
}
26752679
PyType_Modified(typeobj);
2680+
// We try to hold onto a reference to these until after we call
2681+
// PyType_Modified(), in case their deallocation triggers somer user code
2682+
// that tries to do something to the type.
2683+
Py_XDECREF(dunder_dict);
2684+
Py_XDECREF(dunder_weakref);
26762685
Py_RETURN_NONE;
26772686
}
26782687

0 commit comments

Comments
 (0)