Skip to content

Commit

Permalink
Implement traversal for Diagnostics object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dvarrazzo committed May 23, 2017
1 parent 165449c commit 9f6bab6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions psycopg/diagnostics_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,23 @@ diagnostics_init(diagnosticsObject *self, PyObject *args, PyObject *kwds)
return 0;
}

static int
diagnostics_traverse(diagnosticsObject *self, visitproc visit, void *arg)
{
Py_VISIT(self->err);
return 0;
}

static int
diagnostics_clear(diagnosticsObject *self)
{
Py_CLEAR(self->err);
return 0;
}

static void
diagnostics_dealloc(diagnosticsObject* self)
{
Py_CLEAR(self->err);
Py_TYPE(self)->tp_free((PyObject *)self);
}

Expand Down Expand Up @@ -175,10 +188,10 @@ PyTypeObject diagnosticsType = {
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
diagnosticsType_doc, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
(traverseproc)diagnostics_traverse, /*tp_traverse*/
(inquiry)diagnostics_clear, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
Expand Down

0 comments on commit 9f6bab6

Please sign in to comment.