Commit 946de92f authored by Gregory P. Smith's avatar Gregory P. Smith

backport r60544 from trunk:

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.
parent 8af7067a
...@@ -244,6 +244,9 @@ Extension Modules ...@@ -244,6 +244,9 @@ Extension Modules
- Bug #1372: zlibmodule.c: int overflow in PyZlib_decompress - Bug #1372: zlibmodule.c: int overflow in PyZlib_decompress
- bsddb module: Fix memory leak when using database cursors on
databases without a DBEnv.
Documentation Documentation
------------- -------------
......
...@@ -913,7 +913,6 @@ DBCursor_dealloc(DBCursorObject* self) ...@@ -913,7 +913,6 @@ DBCursor_dealloc(DBCursorObject* self)
#endif #endif
if (self->dbc != NULL) { if (self->dbc != NULL) {
MYDB_BEGIN_ALLOW_THREADS;
/* If the underlying database has been closed, we don't /* If the underlying database has been closed, we don't
need to do anything. If the environment has been closed need to do anything. If the environment has been closed
we need to leak, as BerkeleyDB will crash trying to access we need to leak, as BerkeleyDB will crash trying to access
...@@ -922,10 +921,15 @@ DBCursor_dealloc(DBCursorObject* self) ...@@ -922,10 +921,15 @@ DBCursor_dealloc(DBCursorObject* self)
a database open. */ a database open. */
if (self->mydb->db && self->mydb->myenvobj && if (self->mydb->db && self->mydb->myenvobj &&
!self->mydb->myenvobj->closed) !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); err = self->dbc->c_close(self->dbc);
self->dbc = NULL;
MYDB_END_ALLOW_THREADS; MYDB_END_ALLOW_THREADS;
} }
self->dbc = NULL;
}
Py_XDECREF( self->mydb ); Py_XDECREF( self->mydb );
PyObject_Del(self); PyObject_Del(self);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment