Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Jan 4, 2024
1 parent 96194a1 commit 1877f7b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ static PyType_Slot pycstruct_type_slots[] = {
{Py_tp_clear, CDataType_clear},
{Py_tp_methods, CDataType_methods},
{Py_tp_new, PyCStructType_new},

// Sequence protocol.
{Py_sq_repeat, CDataType_repeat},
{0, NULL},
Expand Down Expand Up @@ -1529,14 +1529,21 @@ static int
PyCArrayType_traverse(PyTypeObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
return PyType_Type.tp_traverse((PyObject *)self, visit, arg);
}

static int
PyCArrayType_clear(PyObject *self)
{
return PyType_Type.tp_clear(self);
}

static PyType_Slot pycarray_type_slots[] = {
{Py_tp_doc, PyDoc_STR("metatype for the Array Objects")},
{Py_tp_traverse, PyCArrayType_traverse},
{Py_tp_methods, CDataType_methods},
{Py_tp_new, PyCArrayType_new},
{Py_tp_clear, PyCArrayType_clear},

// Sequence protocol.
{Py_sq_repeat, CDataType_repeat},
Expand Down Expand Up @@ -2192,7 +2199,13 @@ static int
PyCSimpleType_traverse(PyTypeObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
return PyType_Type.tp_traverse((PyObject *)self, visit, arg);
}

static int
PyCSimpleType_clear(PyObject *self)
{
return PyType_Type.tp_clear(self);
}

static PyMethodDef PyCSimpleType_methods[] = {
Expand All @@ -2209,6 +2222,7 @@ static PyType_Slot pycsimple_type_slots[] = {
{Py_tp_methods, PyCSimpleType_methods},
{Py_tp_new, PyCSimpleType_new},
{Py_tp_traverse, PyCSimpleType_traverse},
{Py_tp_clear, PyCSimpleType_clear},

// Sequence protocol.
{Py_sq_repeat, CDataType_repeat},
Expand Down

0 comments on commit 1877f7b

Please sign in to comment.