]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
conscache.c: do not match entries that are slated for removal.
authorNick Mathewson <nickm@torproject.org>
Tue, 11 Apr 2017 19:50:06 +0000 (15:50 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 15 Apr 2017 15:21:32 +0000 (11:21 -0400)
src/or/conscache.c
src/test/test_conscache.c

index 2a6e1445e3a981583060577fcebac944b50860d8..a186163b6c45cba1db52cdda074ef842c7513f84 100644 (file)
@@ -174,6 +174,8 @@ consensus_cache_find_first(consensus_cache_t *cache,
  * Given a <b>cache</b>, add every entry to <b>out<b> for which
  * <b>key</b>=<b>value</b>.  If <b>key</b> is NULL, add every entry.
  *
+ * Do not add any entry that has been marked for removal.
+ *
  * Does not adjust reference counts.
  */
 void
@@ -182,12 +184,15 @@ consensus_cache_find_all(smartlist_t *out,
                          const char *key,
                          const char *value)
 {
-  if (! key) {
-    smartlist_add_all(out, cache->entries);
-    return;
-  }
-
   SMARTLIST_FOREACH_BEGIN(cache->entries, consensus_cache_entry_t *, ent) {
+    if (ent->can_remove == 1) {
+      /* We want to delete this; pretend it isn't there. */
+      continue;
+    }
+    if (! key) {
+      smartlist_add(out, ent);
+      continue;
+    }
     const char *found_val = consensus_cache_entry_get_value(ent, key);
     if (found_val && !strcmp(value, found_val)) {
       smartlist_add(out, ent);
index 12184f0cc6683fc173c6ac0f9dae3055795cb15c..c316411a79eae4df7f599fe0337f3e2b42d67e09 100644 (file)
@@ -200,8 +200,7 @@ test_conscache_cleanup(void *arg)
   tt_assert(e_tmp);
   tt_assert(consensus_cache_entry_is_mapped(e_tmp));
   e_tmp = consensus_cache_find_first(cache, "index", "7");
-  tt_assert(e_tmp);
-  tt_assert(consensus_cache_entry_is_mapped(e_tmp));
+  tt_assert(e_tmp == NULL); // not found because pending deletion.
 
   /* Delete the pending-deletion items. */
   consensus_cache_delete_pending(cache);
@@ -210,12 +209,12 @@ test_conscache_cleanup(void *arg)
     consensus_cache_find_all(entries, cache, NULL, NULL);
     int n = smartlist_len(entries);
     smartlist_free(entries);
-    tt_int_op(n, OP_EQ, 20 - 1); /* 1 entry was deleted */
+    tt_int_op(n, OP_EQ, 20 - 2); /* 1 entry was deleted; 1 is not-found. */
   }
   e_tmp = consensus_cache_find_first(cache, "index", "7"); // refcnt == 1...
   tt_assert(e_tmp == NULL); // so deleted.
   e_tmp = consensus_cache_find_first(cache, "index", "14"); // refcnt == 2
-  tt_assert(e_tmp); // so, not deleted.
+  tt_assert(e_tmp == NULL); // not deleted; but not found.
 
   /* Now do lazy unmapping. */
   // should do nothing.