gh-95324: Emit a warning if an object doesn't call PyObject_GC_UnTrack during deallocation in debug mode (#95325)

This commit is contained in:
Pablo Galindo Salgado 2022-07-27 16:03:38 +01:00 committed by GitHub
parent 2833f3798d
commit f40bc7fa49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 2 deletions

View file

@ -3214,6 +3214,7 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = state->memerrors_freelist;
self->args = PyTuple_New(0);
/* This shouldn't happen since the empty tuple is persistent */
if (self->args == NULL) {
return NULL;
}
@ -3229,6 +3230,8 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
MemoryError_dealloc(PyBaseExceptionObject *self)
{
_PyObject_GC_UNTRACK(self);
BaseException_clear(self);
/* If this is a subclass of MemoryError, we don't need to
@ -3238,8 +3241,6 @@ MemoryError_dealloc(PyBaseExceptionObject *self)
return;
}
_PyObject_GC_UNTRACK(self);
struct _Py_exc_state *state = get_exc_state();
if (state->memerrors_numfree >= MEMERRORS_SAVE) {
Py_TYPE(self)->tp_free((PyObject *)self);