summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-11-26 00:42:25 +0000
committerNick Mathewson <nickm@torproject.org>2005-11-26 00:42:25 +0000
commit72cb64406a5b0d64a27340ced604b99019067c36 (patch)
tree4b9fc08a20d29798756e5b86fd616cf61aa7177c /src/common
parentfe221f3dff3fa1c79213f04261e4c7a70576b619 (diff)
downloadtor-72cb64406a5b0d64a27340ced604b99019067c36.tar.gz
tor-72cb64406a5b0d64a27340ced604b99019067c36.zip
HT_NEXT invalidates the last iterator; fix rmv-related segfault.
svn:r5458
Diffstat (limited to 'src/common')
-rw-r--r--src/common/container.c26
-rw-r--r--src/common/ht.h3
2 files changed, 16 insertions, 13 deletions
diff --git a/src/common/container.c b/src/common/container.c
index d34299254f..09951bae4d 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -756,26 +756,28 @@ digestmap_iter_next(digestmap_t *map, digestmap_iter_t *iter)
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 @@ void
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 @@ void
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;
diff --git a/src/common/ht.h b/src/common/ht.h
index 54b451613a..410fcd3b81 100644
--- a/src/common/ht.h
+++ b/src/common/ht.h
@@ -215,7 +215,7 @@ ht_string_hash(const char *s)
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 @@ ht_string_hash(const char *s)
} \
}
-
#if 0
/* Helpers for an iterator type that saves some mod operations at the expense
* of many branches. Not worth it, it seems. */