From 66fceb9661ef24ed98d79a18fd245c68ed77dfc8 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 6 Aug 2017 15:14:45 +0200 Subject: [PATCH] handle removing of elements in GList correctly When closing a notification in check_timeouts, iter will get removed of the list and therefore iter->next is NULL at the end of the loop. This requires calling check_timeouts again. Shifting iter to iter->next before removing the notification, we can avoid recalling check_timeouts and avoid processing the already processed list again. --- src/dunst.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dunst.c b/src/dunst.c index ce3a8ce..2826d5a 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -57,8 +57,8 @@ void check_timeouts(void) if (displayed->length == 0) return; - for (GList * iter = g_queue_peek_head_link(displayed); iter; - iter = iter->next) { + GList *iter = g_queue_peek_head_link(displayed); + while (iter) { notification *n = iter->data; /* don't timeout when user is idle */ @@ -72,12 +72,12 @@ void check_timeouts(void) continue; } + /* shift iter before we possibly delete the current notification */ + iter = iter->next; + /* remove old message */ if (difftime(time(NULL), n->start) > n->timeout) { - /* close_notification may conflict with iter, so restart */ notification_close(n, 1); - check_timeouts(); - return; } } }