Skip to content

Commit 9f6bab6

Browse files
committed
Implement traversal for Diagnostics object
Triyng to fix a reported memory leak with diags, but implementing traversing doesn't help. Quite the opposite in the example provided in bug #557, the leak is present even with the `del diag`. The leak appears with Python 3.5, not with Python 2.7.
1 parent 165449c commit 9f6bab6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

psycopg/diagnostics_type.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,23 @@ diagnostics_init(diagnosticsObject *self, PyObject *args, PyObject *kwds)
132132
return 0;
133133
}
134134

135+
static int
136+
diagnostics_traverse(diagnosticsObject *self, visitproc visit, void *arg)
137+
{
138+
Py_VISIT(self->err);
139+
return 0;
140+
}
141+
142+
static int
143+
diagnostics_clear(diagnosticsObject *self)
144+
{
145+
Py_CLEAR(self->err);
146+
return 0;
147+
}
148+
135149
static void
136150
diagnostics_dealloc(diagnosticsObject* self)
137151
{
138-
Py_CLEAR(self->err);
139152
Py_TYPE(self)->tp_free((PyObject *)self);
140153
}
141154

@@ -175,10 +188,10 @@ PyTypeObject diagnosticsType = {
175188
0, /*tp_getattro*/
176189
0, /*tp_setattro*/
177190
0, /*tp_as_buffer*/
178-
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
191+
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
179192
diagnosticsType_doc, /*tp_doc*/
180-
0, /*tp_traverse*/
181-
0, /*tp_clear*/
193+
(traverseproc)diagnostics_traverse, /*tp_traverse*/
194+
(inquiry)diagnostics_clear, /*tp_clear*/
182195
0, /*tp_richcompare*/
183196
0, /*tp_weaklistoffset*/
184197
0, /*tp_iter*/

0 commit comments

Comments
 (0)