File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2833,6 +2833,13 @@ subtype_dealloc(PyObject *self)
28332833 }
28342834 }
28352835
2836+ /* Save the current exception: clear_slots() and the dict/base-dealloc
2837+ below decref arbitrary attribute values, which may clear
2838+ tstate->current_exception (gh-89373). Mirroring slot_tp_finalize(). */
2839+ PyThreadState * tstate = _PyThreadState_GET ();
2840+ PyObject * exc = _PyErr_GetRaisedException (tstate ); /* preserve in-flight exception */
2841+
2842+
28362843 /* Clear slots up to the nearest base with a different tp_dealloc */
28372844 base = type ;
28382845 while ((basedealloc = base -> tp_dealloc ) == subtype_dealloc ) {
@@ -2882,6 +2889,9 @@ subtype_dealloc(PyObject *self)
28822889 if (type_needs_decref ) {
28832890 _Py_DECREF_TYPE (type );
28842891 }
2892+
2893+ /* Restore the saved exception (see save above). */
2894+ _PyErr_SetRaisedException (tstate , exc );
28852895}
28862896
28872897static PyTypeObject * solid_base (PyTypeObject * type );
You can’t perform that action at this time.
0 commit comments