summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2008-12-18 23:26:08 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2008-12-18 23:26:08 +0100
commitb933281ed5efb9ad9375c3ea41ee2412b9f89c15 (patch)
treeb90240786203e981319e9e1f3e131689e32f6b55 /lib
parent35164c501722f07beef21178b19090fa9d1930cd (diff)
downloadbird-b933281ed5efb9ad9375c3ea41ee2412b9f89c15.tar
bird-b933281ed5efb9ad9375c3ea41ee2412b9f89c15.zip
Fixes nasty bug in event processing.
WALK_LIST_DELSAFE (in ev_run_list) is not safe with regard to deletion of next node. When some events are rescheduled during event execution, it may lead to deletion of next node and some events are skipped. Such skipped nodes remain in temporary list on stack and the last of them contains 'next' pointer to stack area. When this event is later scheduled, it damages stack area trying to remove it from the list, which leads to random crashes with funny backtraces :-) .
Diffstat (limited to 'lib')
-rw-r--r--lib/event.c4
-rw-r--r--lib/lists.h3
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/event.c b/lib/event.c
index 9b5870d..55a9c48 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -125,13 +125,13 @@ ev_schedule(event *e)
int
ev_run_list(event_list *l)
{
- node *n, *p;
+ node *n;
list tmp_list;
init_list(&tmp_list);
add_tail_list(&tmp_list, l);
init_list(l);
- WALK_LIST_DELSAFE(n, p, tmp_list)
+ WALK_LIST_FIRST(n, tmp_list)
{
event *e = SKIP_BACK(event, n, n);
ev_run(e);
diff --git a/lib/lists.h b/lib/lists.h
index 5b36ec8..342dfd6 100644
--- a/lib/lists.h
+++ b/lib/lists.h
@@ -37,6 +37,9 @@ typedef struct list { /* In fact two overlayed nodes */
n=(void *)((NODE (n))->next))
#define WALK_LIST_DELSAFE(n,nxt,list) \
for(n=HEAD(list); nxt=(void *)((NODE (n))->next); n=(void *) nxt)
+/* WALK_LIST_FIRST supposes that called code removes each processed node */
+#define WALK_LIST_FIRST(n,list) \
+ while(n=HEAD(list), (NODE (n))->next)
#define WALK_LIST_BACKWARDS(n,list) for(n=TAIL(list);(NODE (n))->prev; \
n=(void *)((NODE (n))->prev))
#define WALK_LIST_BACKWARDS_DELSAFE(n,prv,list) \