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.
This commit is contained in:
Nikos Tsipinakis 2017-08-19 20:33:11 +03:00
parent 3c257eaeb7
commit eb0a0f8602

View File

@ -61,6 +61,13 @@ void check_timeouts(void)
while (iter) { while (iter) {
notification *n = iter->data; 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 */ /* don't timeout when user is idle */
if (x_is_idle()) { if (x_is_idle()) {
n->start = time(NULL); n->start = time(NULL);
@ -72,9 +79,6 @@ void check_timeouts(void)
continue; continue;
} }
/* shift iter before we possibly delete the current notification */
iter = iter->next;
/* remove old message */ /* remove old message */
if (difftime(time(NULL), n->start) > n->timeout) { if (difftime(time(NULL), n->start) > n->timeout) {
notification_close(n, 1); notification_close(n, 1);