summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-05-01 13:19:23 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2018-05-03 10:27:43 +0200
commitb047b21e376411a4bda7ed24720feaa9f2a4ecee (patch)
tree1bf023ad7219114a8b52037e03edc44ea41c3799
parentb15d12f7154e80674093597697ffc6af5a4230bf (diff)
downloadouroboros-b047b21e376411a4bda7ed24720feaa9f2a4ecee.tar.gz
ouroboros-b047b21e376411a4bda7ed24720feaa9f2a4ecee.zip
ipcpd: Remove cookie from DHT lookup at update
The lookup struct uses the cookies to track pending request messages, but they were not removed when a response is processed. Upon reuse of a cookie for the next message, it could update the wrong lookup. This removes the cookie for a lookup when it is looked for. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
-rw-r--r--src/ipcpd/normal/dht.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c
index f90f95e4..6d291a35 100644
--- a/src/ipcpd/normal/dht.c
+++ b/src/ipcpd/normal/dht.c
@@ -1021,6 +1021,7 @@ static struct lookup * dht_find_lookup(struct dht * dht,
{
struct list_head * p;
struct list_head * p2;
+ struct list_head * h2;
assert(dht);
assert(cookie > 0);
@@ -1028,10 +1029,12 @@ static struct lookup * dht_find_lookup(struct dht * dht,
list_for_each(p, &dht->lookups) {
struct lookup * l = list_entry(p, struct lookup, next);
pthread_mutex_lock(&l->lock);
- list_for_each(p2, &l->cookies) {
+ list_for_each_safe(p2, h2, &l->cookies) {
struct cookie_el * e;
e = list_entry(p2, struct cookie_el, next);
if (e->cookie == cookie) {
+ list_del(&e->next);
+ free(e);
pthread_mutex_unlock(&l->lock);
return l;
}