From f19d7e5b972e60c843acb3389e8ae07eb6043818 Mon Sep 17 00:00:00 2001 From: Taavi Burns Date: Fri, 19 Nov 2010 17:44:39 -0500 Subject: Fix memory leaks in the cprocessors DecimalResultProcessor, including tests. [ticket:1978] --- lib/sqlalchemy/cextension/processors.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/cextension/processors.c b/lib/sqlalchemy/cextension/processors.c index 327462fa8..193fb19f3 100644 --- a/lib/sqlalchemy/cextension/processors.c +++ b/lib/sqlalchemy/cextension/processors.c @@ -289,6 +289,7 @@ DecimalResultProcessor_process(DecimalResultProcessor *self, PyObject *value) return NULL; str = PyString_Format(self->format, args); + Py_DECREF(args); if (str == NULL) return NULL; @@ -300,6 +301,14 @@ DecimalResultProcessor_process(DecimalResultProcessor *self, PyObject *value) } } +static void +DecimalResultProcessor_dealloc(DecimalResultProcessor *self) +{ + Py_XDECREF(self->type); + Py_XDECREF(self->format); + self->ob_type->tp_free((PyObject*)self); +} + static PyMethodDef DecimalResultProcessor_methods[] = { {"process", (PyCFunction)DecimalResultProcessor_process, METH_O, "The value processor itself."}, @@ -312,7 +321,7 @@ static PyTypeObject DecimalResultProcessorType = { "sqlalchemy.DecimalResultProcessor", /* tp_name */ sizeof(DecimalResultProcessor), /* tp_basicsize */ 0, /* tp_itemsize */ - 0, /* tp_dealloc */ + (destructor)DecimalResultProcessor_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ -- cgit v1.2.1