From b6c9f780741711750c326418a7b4578543b2aa65 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 17 Jan 2003 08:42:50 +0000 Subject: bugfix: do not double-close DB cursor during deallocation when the underlying DB has already been closed (and thus all of its cursors). This fixes a potential segfault. SF pybsddb bug id 667343 bugfix: close the DB object when raising an exception due to an error during DB.open. This prevents an exception when closing the environment about not all databases being closed. SF pybsddb bug id 667340 --- Lib/bsddb/test/test_basics.py | 12 ++++++++++++ Modules/_bsddb.c | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py index 7524b35..25cc77c 100644 --- a/Lib/bsddb/test/test_basics.py +++ b/Lib/bsddb/test/test_basics.py @@ -398,6 +398,18 @@ class BasicTestCase(unittest.TestCase): self.fail("no exception raised when using a buggy cursor's" "%s method" % method) + # + # free cursor referencing a closed database, it should not barf: + # + oldcursor = self.d.cursor(txn=txn) + self.d.close() + + # this would originally cause a segfault when the cursor for a + # closed database was cleaned up. it should not anymore. + # SF pybsddb bug id 667343 + del oldcursor + + #---------------------------------------- def test04_PartialGetAndPut(self): diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 9561d28..396a3cc 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -746,7 +746,8 @@ DBCursor_dealloc(DBCursorObject* self) int err; if (self->dbc != NULL) { MYDB_BEGIN_ALLOW_THREADS; - err = self->dbc->c_close(self->dbc); + if (self->mydb->db != NULL) + err = self->dbc->c_close(self->dbc); self->dbc = NULL; MYDB_END_ALLOW_THREADS; } @@ -1623,6 +1624,7 @@ DB_open(DBObject* self, PyObject* args, PyObject* kwargs) #endif MYDB_END_ALLOW_THREADS; if (makeDBError(err)) { + self->db->close(self->db, 0); self->db = NULL; return NULL; } -- cgit v0.12