diff options
author | Laurent Ghigonis <laurent@p1sec.com> | 2012-07-22 04:10:00 +0200 |
---|---|---|
committer | Laurent Ghigonis <laurent@p1sec.com> | 2012-07-22 04:10:00 +0200 |
commit | a6b51c44b8d52fa159c4dc073c9dafbc4baa18f2 (patch) | |
tree | e773d07173643eeb48706d788158564cf11c0884 /glougloud/user.c | |
parent | fatal() messages are now prefixed by "fatal:" (diff) | |
download | glouglou-a6b51c44b8d52fa159c4dc073c9dafbc4baa18f2.tar.xz glouglou-a6b51c44b8d52fa159c4dc073c9dafbc4baa18f2.zip |
when going through a LIST and removing elements in the loop, you need to
use LIST_FOREACH_SAFE !
Diffstat (limited to 'glougloud/user.c')
-rw-r--r-- | glougloud/user.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/glougloud/user.c b/glougloud/user.c index 998f666..3ed52f4 100644 --- a/glougloud/user.c +++ b/glougloud/user.c @@ -2,7 +2,6 @@ #include <sys/socket.h> #include <sys/param.h> #include <sys/time.h> -#include <sys/queue.h> #if !defined(__OpenBSD__) #define __FAVOR_BSD @@ -512,6 +511,8 @@ conn_del(struct conn *c) p.delconn_id = c->id; sendto_all(&p, PACKET_DELCONN_SIZE); + if (cap->conn_freeids_ptr == 0) + fatal("cap->conn_freeids_ptr == 0"); cap->conn_freeids_ptr--; cap->conn_freeids[cap->conn_freeids_ptr] = c->id; @@ -656,15 +657,15 @@ ev_pcap(int fd, short why, void *data) static void ev_timer(int fd, short why, void *data) { - struct conn *c; - struct node *n; + struct conn *c, *ctmp; + struct node *n, *ntmp; int i, to; log_debug("ev_timer"); cap->time = time(NULL); i = 0; - LIST_FOREACH(c, &cap->conn_list, entry) { + LIST_FOREACH_SAFE(c, &cap->conn_list, entry, ctmp) { switch (c->proto) { case IPPROTO_UDP: to = CONN_TIMEOUT_UDP; @@ -683,7 +684,7 @@ ev_timer(int fd, short why, void *data) } if (cap->node_count > NODE_MAX_WITHOUT_TIMEOUT) { - LIST_FOREACH(n, &cap->node_list, entry) { + LIST_FOREACH_SAFE(n, &cap->node_list, entry, ntmp) { if (n->used == 0 && cap->time > n->lastseen + NODE_TIMEOUT) node_del(n); |