summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/cextension
diff options
context:
space:
mode:
authorGaëtan de Menten <gdementen@gmail.com>2010-11-27 22:27:42 +0100
committerGaëtan de Menten <gdementen@gmail.com>2010-11-27 22:27:42 +0100
commit20418096d5862ed40f22b6c7b7cc53dd212bbd21 (patch)
tree564cb709dc0d96d6b47754d898cfd362ff6bd850 /lib/sqlalchemy/cextension
parent77f641429f019d06cc467ec4e57ae94f808d70bd (diff)
downloadsqlalchemy-20418096d5862ed40f22b6c7b7cc53dd212bbd21.tar.gz
fixed a small potential memory leak in UnicodeResultProcessor (for some weird
reason, it didn't actually leak in my tests) by providing a dealloc method to the type, and added a test to ensure it stays that way. Closes #1981.
Diffstat (limited to 'lib/sqlalchemy/cextension')
-rw-r--r--lib/sqlalchemy/cextension/processors.c10
-rw-r--r--lib/sqlalchemy/cextension/resultproxy.c12
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/sqlalchemy/cextension/processors.c b/lib/sqlalchemy/cextension/processors.c
index 193fb19f3..36745c817 100644
--- a/lib/sqlalchemy/cextension/processors.c
+++ b/lib/sqlalchemy/cextension/processors.c
@@ -204,6 +204,14 @@ UnicodeResultProcessor_process(UnicodeResultProcessor *self, PyObject *value)
return PyUnicode_Decode(str, len, encoding, errors);
}
+static void
+UnicodeResultProcessor_dealloc(UnicodeResultProcessor *self)
+{
+ Py_XDECREF(self->encoding);
+ Py_XDECREF(self->errors);
+ self->ob_type->tp_free((PyObject*)self);
+}
+
static PyMethodDef UnicodeResultProcessor_methods[] = {
{"process", (PyCFunction)UnicodeResultProcessor_process, METH_O,
"The value processor itself."},
@@ -216,7 +224,7 @@ static PyTypeObject UnicodeResultProcessorType = {
"sqlalchemy.cprocessors.UnicodeResultProcessor", /* tp_name */
sizeof(UnicodeResultProcessor), /* tp_basicsize */
0, /* tp_itemsize */
- 0, /* tp_dealloc */
+ (destructor)UnicodeResultProcessor_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c
index 73e127345..93471073b 100644
--- a/lib/sqlalchemy/cextension/resultproxy.c
+++ b/lib/sqlalchemy/cextension/resultproxy.c
@@ -107,11 +107,11 @@ BaseRowProxy_init(BaseRowProxy *self, PyObject *args, PyObject *kwds)
static PyObject *
BaseRowProxy_reduce(PyObject *self)
{
- PyObject *method, *state;
- PyObject *module, *reconstructor, *cls;
+ PyObject *method, *state;
+ PyObject *module, *reconstructor, *cls;
- method = PyObject_GetAttrString(self, "__getstate__");
- if (method == NULL)
+ method = PyObject_GetAttrString(self, "__getstate__");
+ if (method == NULL)
return NULL;
state = PyObject_CallObject(method, NULL);
@@ -503,8 +503,8 @@ static PyGetSetDef BaseRowProxy_getseters[] = {
static PyMethodDef BaseRowProxy_methods[] = {
{"values", (PyCFunction)BaseRowProxy_values, METH_NOARGS,
"Return the values represented by this BaseRowProxy as a list."},
- {"__reduce__", (PyCFunction)BaseRowProxy_reduce, METH_NOARGS,
- "Pickle support method."},
+ {"__reduce__", (PyCFunction)BaseRowProxy_reduce, METH_NOARGS,
+ "Pickle support method."},
{NULL} /* Sentinel */
};