Skip to content

Commit d680b17

Browse files
committed
Don't clobber current exception in tp_dealloc
1 parent 619eac7 commit d680b17

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Modules/xxlimited.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,22 @@ Xxo_finalize(PyObject *self)
257257
}
258258

259259
// dealloc: drop all remaining references and free memory
260+
// This function must preserve currently raised exception, if any.
260261
static void
261262
Xxo_dealloc(PyObject *self)
262263
{
264+
PyObject *exc = PyErr_GetRaisedException();
263265
PyObject_GC_UnTrack(self);
264266
Xxo_finalize(self);
265267
PyTypeObject *tp = Py_TYPE(self);
266268
freefunc free = PyType_GetSlot(tp, Py_tp_free);
267269
free(self);
268270
Py_DECREF(tp);
271+
272+
if (PyErr_Occurred()) {
273+
PyErr_WriteUnraisable(NULL);
274+
}
275+
PyErr_SetRaisedException(exc);
269276
}
270277

271278

0 commit comments

Comments
 (0)