]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
r15967@catbus: nickm | 2007-10-19 14:14:47 -0400
authorNick Mathewson <nickm@torproject.org>
Fri, 19 Oct 2007 18:56:28 +0000 (18:56 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 19 Oct 2007 18:56:28 +0000 (18:56 +0000)
 Change meaning of "freefn" argument to smartlist_uniq so that we can remove duplicates from a list without freeing them.

svn:r12053

src/common/container.c
src/or/routerparse.c
src/or/test.c

index f2a80208b38492d6f06ffad84958fa81b78d32aa..3432bd084b1239b648e08eabd467fd6b9584945b 100644 (file)
@@ -471,8 +471,7 @@ smartlist_sort(smartlist_t *sl, int (*compare)(const void **a, const void **b))
 
 /** Given a sorted smartlist <b>sl</b> and the comparison function used to
  * sort it, remove all duplicate members.  If free_fn is provided, calls
- * free_fn on each duplicate.  Otherwise, frees them with tor_free(), which
- * may not be what you want..  Preserves order.
+ * free_fn on each duplicate.  Otherwise, just removes them.  Preserves order.
  */
 void
 smartlist_uniq(smartlist_t *sl,
@@ -485,8 +484,6 @@ smartlist_uniq(smartlist_t *sl,
                 (const void **)&(sl->list[i])) == 0) {
       if (free_fn)
         free_fn(sl->list[i]);
-      else
-        tor_free(sl->list[i]);
       smartlist_del_keeporder(sl, i--);
     }
   }
@@ -530,7 +527,7 @@ smartlist_sort_strings(smartlist_t *sl)
 void
 smartlist_uniq_strings(smartlist_t *sl)
 {
-  smartlist_uniq(sl, _compare_string_ptrs, NULL);
+  smartlist_uniq(sl, _compare_string_ptrs, _tor_free);
 }
 
 /* Heap-based priority queue implementation for O(lg N) insert and remove.
@@ -653,7 +650,7 @@ smartlist_sort_digests(smartlist_t *sl)
 void
 smartlist_uniq_digests(smartlist_t *sl)
 {
-  smartlist_uniq(sl, _compare_digests, NULL);
+  smartlist_uniq(sl, _compare_digests, _tor_free);
 }
 
 #define DEFINE_MAP_STRUCTS(maptype, keydecl, prefix)      \
index 119345b1dd4df47199e024db99fa15aea10edec6..c634ade44d747f627a46b9e408cb58d86f9ab858 100644 (file)
@@ -3119,6 +3119,6 @@ sort_version_list(smartlist_t *versions, int remove_duplicates)
   smartlist_sort(versions, _compare_tor_version_str_ptr);
 
   if (remove_duplicates)
-    smartlist_uniq(versions, _compare_tor_version_str_ptr, NULL);
+    smartlist_uniq(versions, _compare_tor_version_str_ptr, _tor_free);
 }
 
index 6f242e49584dd73def25af9d446f8e1248013831..3d2c6079df7c8d301b6af00f49d0c30a1d8ff01d 100644 (file)
@@ -1469,7 +1469,7 @@ test_util_smartlist(void)
                      "50,noon,radar,a,man,a,plan,a,canal,panama,radar,noon,50",
                      ",", 0, 0);
   smartlist_sort(sl, _compare_strs);
-  smartlist_uniq(sl, _compare_strs, NULL);
+  smartlist_uniq(sl, _compare_strs, _tor_free);
   cp = smartlist_join_strings(sl, ",", 0, NULL);
   test_streq(cp, "50,a,canal,man,noon,panama,plan,radar");
   tor_free(cp);