]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed memory leak in core which would
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Mar 2012 00:18:52 +0000 (16:18 -0800)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Mar 2012 00:18:52 +0000 (16:18 -0800)
  occur when C extensions were used with
  particular types of result fetches,
  in particular when orm query.count()
  were called.  [ticket:2427]

CHANGES
lib/sqlalchemy/cextension/resultproxy.c
test/aaa_profiling/test_memusage.py

diff --git a/CHANGES b/CHANGES
index c98b80f569ee931aeb95a99caa408ea9b7c01282..cc5f66348457440da58e4265ad08a3f094c6bbb8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -69,6 +69,12 @@ CHANGES
     on the method object.  [ticket:2352]
 
 - sql
+  - [bug] Fixed memory leak in core which would
+    occur when C extensions were used with
+    particular types of result fetches,
+    in particular when orm query.count()
+    were called.  [ticket:2427]
+
   - [feature] Added support for SQL standard
     common table expressions (CTE), allowing
     SELECT objects as the CTE source (DML
index 64b6855faa8fcd22c1b5457535c749eb79ac0a83..325007c117444b842e7026848c24618b61d90d01 100644 (file)
@@ -246,6 +246,7 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key)
     PyObject *exc_module, *exception;
     char *cstr_key;
     long index;
+    int key_fallback = 0;
 
     if (PyInt_CheckExact(key)) {
         index = PyInt_AS_LONG(key);
@@ -276,12 +277,17 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key)
                                          "O", key);
             if (record == NULL)
                 return NULL;
+            key_fallback = 1;
         }
 
         indexobject = PyTuple_GetItem(record, 2);
         if (indexobject == NULL)
             return NULL;
 
+        if (key_fallback) {
+            Py_DECREF(record);
+        }
+
         if (indexobject == Py_None) {
             exc_module = PyImport_ImportModule("sqlalchemy.exc");
             if (exc_module == NULL)
index 579555c3f6ff590ead1da24846e2be8a69f4b50f..cffe8b71f7147ea851fb1c1f0092ce9e46a6051e 100644 (file)
@@ -496,6 +496,22 @@ class MemUsageTest(EnsureZeroed):
             metadata.drop_all()
         assert_no_mappers()
 
+    @testing.fails_if(lambda : testing.db.dialect.name == 'sqlite' \
+                      and testing.db.dialect.dbapi.version > '2.5')
+    @testing.provide_metadata
+    def test_key_fallback_result(self):
+        e = testing.db
+        m = self.metadata
+        t = Table('t', m, Column('x', Integer), Column('y', Integer))
+        m.create_all(e)
+        e.execute(t.insert(), {"x":1, "y":1})
+        @profile_memory
+        def go():
+            r = e.execute(t.alias().select())
+            for row in r:
+                row[t.c.x]
+        go()
+
     # fails on newer versions of pysqlite due to unusual memory behvior
     # in pysqlite itself. background at:
     # http://thread.gmane.org/gmane.comp.python.db.pysqlite.user/2290