]> granicus.if.org Git - python/commitdiff
Merge this fix from the pybsddb tree:
authorGregory P. Smith <greg@mad-scientist.com>
Sun, 3 Feb 2008 07:20:53 +0000 (07:20 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sun, 3 Feb 2008 07:20:53 +0000 (07:20 +0000)
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 4a74446bad8f44ed19574a1d93a099fbf62eaedc..f6c93b7b314e205b6b1de4fc08e030142a207279 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1270,6 +1270,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.
+
 Tests
 -----
 
index f40743493c3723ec1065e812df68df9b3612f6f6..7d05b24ed1d32268cbc59c010cf3830e73e37de2 100644 (file)
@@ -824,7 +824,6 @@ DBCursor_dealloc(DBCursorObject* self)
     }
 
     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
@@ -833,9 +832,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);