Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-104456: Fix ref leak in _ctypes.COMError #104457

Merged
merged 5 commits into from
May 14, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5476,10 +5476,24 @@ comerror_init(PyObject *self, PyObject *args, PyObject *kwds)
return 0;
}

static int
comerror_clear(PyObject *self) {
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
PyBaseExceptionObject *obj = (PyBaseExceptionObject *) self;
Py_CLEAR(obj->dict);
Py_CLEAR(obj->args);
Py_CLEAR(obj->notes);
Py_CLEAR(obj->traceback);
Py_CLEAR(obj->cause);
Py_CLEAR(obj->context);
return 0;
sunmy2019 marked this conversation as resolved.
Show resolved Hide resolved
}

static int
comerror_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
PyTypeObject *tp = Py_TYPE(self);
Py_VISIT(tp);
tp->tp_clear(self);
sunmy2019 marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}

Expand All @@ -5488,6 +5502,7 @@ comerror_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
tp->tp_clear(self);
Eclips4 marked this conversation as resolved.
Show resolved Hide resolved
tp->tp_free(self);
Py_DECREF(tp);
}
Expand All @@ -5497,6 +5512,7 @@ static PyType_Slot comerror_slots[] = {
{Py_tp_init, comerror_init},
{Py_tp_traverse, comerror_traverse},
{Py_tp_dealloc, comerror_dealloc},
{Py_tp_clear, comerror_clear},
{0, NULL},
};

Expand Down