From: Jonathan McDowell Date: Wed, 11 Apr 2012 05:27:02 +0000 (+0100) Subject: Fix deletion of skshash in DB4 backend X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/d393825d164f31fe0194221b6ed90f3c320d8d44 Fix deletion of skshash in DB4 backend We need to delete the skshash while we still have the publickey structure, so we can calculate the hash to free. --- diff --git a/keydb_db4.c b/keydb_db4.c index d3caa37..802903c 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -912,6 +912,42 @@ static int db4_delete_key(uint64_t keyid, bool intrans) ret = cursor->c_close(cursor); cursor = NULL; + ret = skshashdb->cursor(skshashdb, + txn, + &cursor, + 0); /* flags */ + get_skshash(publickey, &hash); + + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + key.data = hash.hash; + key.size = sizeof(hash.hash); + data.data = &keyid; + data.size = sizeof(keyid); + + ret = cursor->c_get(cursor, + &key, + &data, + DB_GET_BOTH); + + if (ret == 0) { + ret = cursor->c_del(cursor, 0); + } + + if (ret != 0) { + logthing(LOGTHING_ERROR, + "Problem deleting skshash: %s " + "(0x%016" PRIX64 ")", + db_strerror(ret), + keyid); + if (ret == DB_LOCK_DEADLOCK) { + deadlock = true; + } + } + + ret = cursor->c_close(cursor); + cursor = NULL; + /* * Free our UID and word lists. */ @@ -1002,44 +1038,6 @@ static int db4_delete_key(uint64_t keyid, bool intrans) } - if (!deadlock) { - ret = skshashdb->cursor(skshashdb, - txn, - &cursor, - 0); /* flags */ - get_skshash(publickey, &hash); - - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - key.data = hash.hash; - key.size = sizeof(hash.hash); - data.data = &keyid; - data.size = sizeof(keyid); - - ret = cursor->c_get(cursor, - &key, - &data, - DB_GET_BOTH); - - if (ret == 0) { - ret = cursor->c_del(cursor, 0); - } - - if (ret != 0) { - logthing(LOGTHING_ERROR, - "Problem deleting skshash: %s " - "(0x%016" PRIX64 ")", - db_strerror(ret), - keyid); - if (ret == DB_LOCK_DEADLOCK) { - deadlock = true; - } - } - - ret = cursor->c_close(cursor); - cursor = NULL; - } - if (!deadlock) { key.data = &keyid; key.size = sizeof(keyid);