[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] HT_NEXT invalidates the last iterator; fix rmv-related segf...



Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv26421/src/common

Modified Files:
	container.c ht.h 
Log Message:
HT_NEXT invalidates the last iterator; fix rmv-related segfault.

Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- container.c	25 Nov 2005 02:16:10 -0000	1.50
+++ container.c	26 Nov 2005 00:42:25 -0000	1.51
@@ -756,26 +756,28 @@
 strmap_iter_t *
 strmap_iter_next_rmv(strmap_t *map, strmap_iter_t *iter)
 {
-  strmap_iter_t *next;
+  strmap_entry_t *rmv;
   tor_assert(map);
   tor_assert(iter);
-  next = HT_NEXT_RMV(strmap_tree, &map->head, iter);
-  if (*iter) {
-    tor_free((*iter)->key);
-    tor_free(*iter);
-  }
-  return next;
+  tor_assert(*iter);
+  rmv = *iter;
+  iter = HT_NEXT_RMV(strmap_tree, &map->head, iter);
+  tor_free(rmv->key);
+  tor_free(rmv);
+  return iter;
 }
 
 digestmap_iter_t *
 digestmap_iter_next_rmv(digestmap_t *map, digestmap_iter_t *iter)
 {
-  digestmap_iter_t *next;
+  digestmap_entry_t *rmv;
   tor_assert(map);
   tor_assert(iter);
-  next = HT_NEXT_RMV(digestmap_tree, &map->head, iter);
-  tor_free(*iter);
-  return next;
+  tor_assert(*iter);
+  rmv = *iter;
+  iter = HT_NEXT_RMV(digestmap_tree, &map->head, iter);
+  tor_free(rmv);
+  return iter;
 }
 
 /** Set *keyp and *valp to the current entry pointed to by iter.
@@ -784,6 +786,7 @@
 strmap_iter_get(strmap_iter_t *iter, const char **keyp, void **valp)
 {
   tor_assert(iter);
+  tor_assert(*iter);
   tor_assert(keyp);
   tor_assert(valp);
   *keyp = (*iter)->key;
@@ -794,6 +797,7 @@
 digestmap_iter_get(digestmap_iter_t *iter, const char **keyp, void **valp)
 {
   tor_assert(iter);
+  tor_assert(*iter);
   tor_assert(keyp);
   tor_assert(valp);
   *keyp = (*iter)->key;

Index: ht.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/ht.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ht.h	23 Nov 2005 04:18:45 -0000	1.1
+++ ht.h	26 Nov 2005 00:42:25 -0000	1.2
@@ -215,7 +215,7 @@
   static __inline struct type **                                        \
   name##_HT_START(struct name *head)                                    \
   {                                                                     \
-    unsigned b = 0;                                                 \
+    unsigned b = 0;                                                     \
     while (b < head->hth_table_length) {                                \
       if (head->hth_table[b])                                           \
         return &head->hth_table[b];                                     \
@@ -262,7 +262,6 @@
     }                                                                   \
   }
 
-
 #if 0
 /* Helpers for an iterator type that saves some mod operations at the expense
  * of many branches. Not worth it, it seems. */