From eb0a0f860274f0058e3124c8ccd1f007ef0222c9 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Sat, 19 Aug 2017 20:33:11 +0300 Subject: [PATCH] Fix infinite loop when checking timeouts Move the iter pointer to the next item before doing any logic that might result in exiting from the current iteration of the loop since it would cause the same notification to be processed repeatedly resulting in an infinite loop. Fixes 362. --- src/dunst.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dunst.c b/src/dunst.c index d2893f9..b036500 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -61,6 +61,13 @@ void check_timeouts(void) while (iter) { notification *n = iter->data; + /* + * Update iter to the next item before we either exit the + * current iteration of the loop or potentially delete the + * notification which would invalidate the pointer. + */ + iter = iter->next; + /* don't timeout when user is idle */ if (x_is_idle()) { n->start = time(NULL); @@ -72,9 +79,6 @@ 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) { notification_close(n, 1);