diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-01 16:22:44 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-01 16:22:44 -0400 |
| commit | c6d599f99344c840db5cc5422537310b83981fda (patch) | |
| tree | 27a76e94bc479475fb4d0358a32bb796459d9020 /lib/sqlalchemy/cextension | |
| parent | cc947a4da70c906ac1820db6ccdd7f0faa8a2ced (diff) | |
| download | sqlalchemy-c6d599f99344c840db5cc5422537310b83981fda.tar.gz | |
- [bug] Fixed memory leak in C version of
result proxy whereby DBAPIs which don't deliver
pure Python tuples for result rows would
fail to decrement refcounts correctly.
The most prominently affected DBAPI
is pyodbc. [ticket:2489]
Diffstat (limited to 'lib/sqlalchemy/cextension')
| -rw-r--r-- | lib/sqlalchemy/cextension/resultproxy.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index 3494ccae6..518209e54 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -241,13 +241,14 @@ static PyObject * BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) { PyObject *processors, *values; - PyObject *processor, *value; + PyObject *processor, *value, *processed_value; PyObject *row, *record, *result, *indexobject; PyObject *exc_module, *exception; char *cstr_key; long index; int key_fallback = 0; - + int tuple_check = 0; + if (PyInt_CheckExact(key)) { index = PyInt_AS_LONG(key); } else if (PyLong_CheckExact(key)) { @@ -319,17 +320,28 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) return NULL; row = self->row; - if (PyTuple_CheckExact(row)) + if (PyTuple_CheckExact(row)) { value = PyTuple_GetItem(row, index); - else + tuple_check = 1; + } + else { value = PySequence_GetItem(row, index); + tuple_check = 0; + } + if (value == NULL) return NULL; if (processor != Py_None) { - return PyObject_CallFunctionObjArgs(processor, value, NULL); + processed_value = PyObject_CallFunctionObjArgs(processor, value, NULL); + if (!tuple_check) { + Py_DECREF(value); + } + return processed_value; } else { - Py_INCREF(value); + if (tuple_check) { + Py_INCREF(value); + } return value; } } |
