X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/28052481c1892cd06a2626a1ecd7221c3814f0e6..23817f46df40d242f476a82f677bd8aa22f22aca:/keydb_db4.c?ds=inline diff --git a/keydb_db4.c b/keydb_db4.c index 04949d0..0163ed5 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -6,7 +6,6 @@ * Copyright 2002-2004 Project Purple */ -#include #include #include #include @@ -225,17 +224,25 @@ void cleanupdb(void) { int i = 0; - dbenv->txn_checkpoint(dbenv, 0, 0, 0); - id32db->close(id32db, 0); - id32db = NULL; - worddb->close(worddb, 0); - worddb = NULL; - for (i = 0; i < numdbs; i++) { - dbconns[i]->close(dbconns[i], 0); - dbconns[i] = NULL; + if (dbenv != NULL) { + dbenv->txn_checkpoint(dbenv, 0, 0, 0); + if (id32db != NULL) { + id32db->close(id32db, 0); + id32db = NULL; + } + if (worddb != NULL) { + worddb->close(worddb, 0); + worddb = NULL; + } + for (i = 0; i < numdbs; i++) { + if (dbconns[i] != NULL) { + dbconns[i]->close(dbconns[i], 0); + dbconns[i] = NULL; + } + } + dbenv->close(dbenv, 0); + dbenv = NULL; } - dbenv->close(dbenv, 0); - dbenv = NULL; } /** @@ -249,8 +256,8 @@ bool starttrans(void) { int ret; - assert(dbenv != NULL); - assert(txn == NULL); + log_assert(dbenv != NULL); + log_assert(txn == NULL); ret = dbenv->txn_begin(dbenv, NULL, /* No parent transaction */ @@ -275,8 +282,8 @@ void endtrans(void) { int ret; - assert(dbenv != NULL); - assert(txn != NULL); + log_assert(dbenv != NULL); + log_assert(txn != NULL); ret = txn->commit(txn, 0); @@ -631,10 +638,6 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update) uids = NULL; } - if (!intrans) { - endtrans(); - } - /* * Write the truncated 32 bit keyid so we can lookup the full id for * queries. @@ -697,6 +700,10 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update) } } + if (!intrans) { + endtrans(); + } + return deadlock ? -1 : 0 ; }