]> granicus.if.org Git - python/commitdiff
backport r60544 from trunk:
authorGregory P. Smith <greg@mad-scientist.com>
Sun, 3 Feb 2008 07:26:23 +0000 (07:26 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sun, 3 Feb 2008 07:26:23 +0000 (07:26 +0000)
Merge this fix from the pybsddb tree:
r293 | jcea | 2008-01-31 01:08:19 -0800 (Thu, 31 Jan 2008) | 4 lines

Solved memory leak when using cursors with
databases without environment.

Misc/NEWS
Modules/_bsddb.c

index 0a369adb81ab7c58f641819ea86901f743921c84..d83b9cf49c3e42b5f5a196899aeecd38f44a61aa 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -244,6 +244,9 @@ Extension Modules
 
 - Bug #1372: zlibmodule.c: int overflow in PyZlib_decompress
 
+- bsddb module: Fix memory leak when using database cursors on
+  databases without a DBEnv.
+
 
 Documentation
 -------------
index 943a4ea0e77df08f3df8748282229926a811264c..4cedc98d7b15c717a647fff28b804ebde9fcf5c8 100644 (file)
@@ -913,7 +913,6 @@ DBCursor_dealloc(DBCursorObject* self)
 #endif
 
     if (self->dbc != NULL) {
-        MYDB_BEGIN_ALLOW_THREADS;
        /* If the underlying database has been closed, we don't
           need to do anything. If the environment has been closed
           we need to leak, as BerkeleyDB will crash trying to access
@@ -922,9 +921,14 @@ DBCursor_dealloc(DBCursorObject* self)
           a database open. */
        if (self->mydb->db && self->mydb->myenvobj &&
            !self->mydb->myenvobj->closed)
+        /* test for: open db + no environment or non-closed environment */
+       if (self->mydb->db && (!self->mydb->myenvobj || (self->mydb->myenvobj &&
+           !self->mydb->myenvobj->closed))) {
+            MYDB_BEGIN_ALLOW_THREADS;
             err = self->dbc->c_close(self->dbc);
+            MYDB_END_ALLOW_THREADS;
+        }
         self->dbc = NULL;
-        MYDB_END_ALLOW_THREADS;
     }
     Py_XDECREF( self->mydb );
     PyObject_Del(self);