From b047b21e376411a4bda7ed24720feaa9f2a4ecee Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 1 May 2018 13:19:23 +0200 Subject: 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 Signed-off-by: Sander Vrijders --- src/ipcpd/normal/dht.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3