summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-05-18 12:24:48 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-05-23 11:37:19 +0100
commit9f6bab692d6d84cfbe5797e963225fc002bfa3d5 (patch)
tree42cb6effbcb418d46efb3986306e87be3389b746
parent165449c724fe880a1b6ef3ffbe39d65a8e5a43aa (diff)
downloadpsycopg2-bug-557.tar.gz
Implement traversal for Diagnostics objectbug-557
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.
-rw-r--r--psycopg/diagnostics_type.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/psycopg/diagnostics_type.c b/psycopg/diagnostics_type.c
index 0af6526..cdaf62f 100644
--- a/psycopg/diagnostics_type.c
+++ b/psycopg/diagnostics_type.c
@@ -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);
}
@@ -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*/