]> the.earth.li Git - onak.git/commitdiff
Fix deletion of skshash in DB4 backend
authorJonathan McDowell <noodles@earth.li>
Wed, 11 Apr 2012 05:27:02 +0000 (06:27 +0100)
committerJonathan McDowell <noodles@earth.li>
Wed, 11 Apr 2012 05:27:02 +0000 (06:27 +0100)
  We need to delete the skshash while we still have the publickey
  structure, so we can calculate the hash to free.

keydb_db4.c

index d3caa37be9480ce4056aa68edf1f9fc38a789246..802903caed6b8c373ab0ece3843494c19ebb74e5 100644 (file)
@@ -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);