Skip to content

Commit 0ebfcd5

Browse files
committed
Added tp_dealloc for cursor object
1 parent 11a22ad commit 0ebfcd5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mariadb/mariadb_cursor.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static PyObject *
6969
MrdbCursor_readresponse(MrdbCursor *self);
7070

7171
PyObject *MrdbCursor_clear_result(MrdbCursor *self);
72+
static void ma_cursor_close(MrdbCursor *self);
7273

7374
void
7475
field_fetch_callback(void *data, unsigned int column, unsigned char **row);
@@ -346,20 +347,28 @@ static PyObject *MrdbCursor_repr(MrdbCursor *self)
346347
return PyUnicode_FromString(cobj_repr);
347348
}
348349

350+
static void MrdbCursor_dealloc(PyObject *obj)
351+
{
352+
MrdbCursor *self = (MrdbCursor *)obj;
353+
ma_cursor_close(self);
354+
Py_TYPE(self)->tp_free((PyObject *)self);
355+
}
356+
349357
PyTypeObject MrdbCursor_Type =
350358
{
351359
PyVarObject_HEAD_INIT(NULL, 0)
352360
.tp_name = "mariadb.cursor",
353361
.tp_basicsize= (Py_ssize_t)sizeof(MrdbCursor),
354-
.tp_repr= (reprfunc)MrdbCursor_repr,
362+
.tp_repr= (reprfunc)MrdbCursor_repr,
355363
.tp_flags= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
356-
.tp_doc= mariadb_cursor_documentation,
364+
.tp_doc= mariadb_cursor_documentation,
357365
.tp_traverse= (traverseproc)MrdbCursor_traverse,/* tp_traverse */
358366
.tp_methods= (struct PyMethodDef *)MrdbCursor_Methods,
359367
.tp_members= (struct PyMemberDef *)MrdbCursor_Members,
360368
.tp_getset= MrdbCursor_sets,
361369
.tp_init= (initproc)MrdbCursor_initialize,
362370
.tp_new= PyType_GenericNew,
371+
.tp_dealloc= MrdbCursor_dealloc,
363372
.tp_finalize= (destructor)MrdbCursor_finalize
364373
};
365374

0 commit comments

Comments
 (0)