]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Wed, 25 Jan 2006 05:29:17 +0000 (05:29 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Wed, 25 Jan 2006 05:29:17 +0000 (05:29 +0000)
Fix bug #1413192, fix seg fault in bsddb if a txn was deleted before the env.

Lib/bsddb/test/test_1413192.py [new file with mode: 0644]
Lib/bsddb/test/test_all.py
Lib/test/test_bsddb3.py
Misc/NEWS
Modules/_bsddb.c

diff --git a/Lib/bsddb/test/test_1413192.py b/Lib/bsddb/test/test_1413192.py
new file mode 100644 (file)
index 0000000..45afb36
--- /dev/null
@@ -0,0 +1,16 @@
+
+# http://python.org/sf/1413192
+#
+# This test relies on the variable names, see the bug report for details.
+# The problem was that the env was deallocated prior to the txn.
+
+from bsddb import db
+
+env_name = '.'
+
+env = db.DBEnv()
+env.open(env_name, db.DB_CREATE | db.DB_INIT_TXN)
+the_txn = env.txn_begin()
+
+map = db.DB(env)
+map.open('xxx.db', "p", db.DB_HASH, db.DB_CREATE, 0666, txn=the_txn)
index 7b1bf3d29428ac7c03e5f345af60bdf22d3a603b..23dba0c098e600176c59d3d9b09c4e3f29625b5c 100644 (file)
@@ -46,6 +46,12 @@ test_all.verbose = verbose
 
 
 def suite():
+    try:
+        # this is special, it used to segfault the interpreter
+        import test_1413192
+    except:
+        pass
+
     test_modules = [
         'test_associate',
         'test_basics',
index cd6ccc6053ccb467d6a54864a79e0c5aad59887a..34555ff33b93a5383479ed81f9e9b0301e5d2e68 100644 (file)
@@ -22,6 +22,12 @@ if 'silent' in sys.argv:  # take care of old flag, just in case
 
 
 def suite():
+    try:
+        # this is special, it used to segfault the interpreter
+        import bsddb.test.test_1413192
+    except:
+        pass
+
     test_modules = [
         'test_associate',
         'test_basics',
index 8382e86c58229aa0a4d6202b6c189c5abef03572..e23712b2ffaefc79b938157840952914c1a03d80 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -208,6 +208,9 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Bug #1413192, fix seg fault in bsddb if a transaction was deleted
+  before the env.
+
 - Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...)
 
 - Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints.
index 0ef797ca329a91e2413d1379cdaca949fc4f40a1..c6efa1cc901a8d6b5f7e95c5bfaea3e8121ec294 100644 (file)
@@ -265,6 +265,7 @@ typedef struct {
 typedef struct {
     PyObject_HEAD
     DB_TXN*         txn;
+    PyObject        *env;
 #ifdef HAVE_WEAKREF
     PyObject        *in_weakreflist; /* List of weak references */
 #endif
@@ -921,6 +922,8 @@ newDBTxnObject(DBEnvObject* myenv, DB_TXN *parent, int flags)
     DBTxnObject* self = PyObject_New(DBTxnObject, &DBTxn_Type);
     if (self == NULL)
         return NULL;
+    Py_INCREF(myenv);
+    self->env = (PyObject*)myenv;
 #ifdef HAVE_WEAKREF
     self->in_weakreflist = NULL;
 #endif
@@ -931,11 +934,10 @@ newDBTxnObject(DBEnvObject* myenv, DB_TXN *parent, int flags)
 #else
     err = txn_begin(myenv->db_env, parent, &(self->txn), flags);
 #endif
-    /* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs
-     * list so that a DBEnv can refuse to close without aborting any open
-     * open DBTxns and closing any open DBs first. */
     MYDB_END_ALLOW_THREADS;
     if (makeDBError(err)) {
+        Py_DECREF(self->env);
+        PyObject_Del(self);
         self = NULL;
     }
     return self;
@@ -966,6 +968,7 @@ DBTxn_dealloc(DBTxnObject* self)
     }
 #endif
 
+    Py_DECREF(self->env);
     PyObject_Del(self);
 }