]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: don't return currently used timeout ID
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 10 Nov 2015 13:41:19 +0000 (14:41 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 16 Nov 2015 09:25:33 +0000 (10:25 +0100)
To avoid problems in the very unlikely case where a timeout is so long
and new IDs are allocated so frequently that they would have a chance
to overflow and catch up with it, make sure before returning new ID that
it's currently not in use.

sched.c

diff --git a/sched.c b/sched.c
index bd8add0390828ed36c2c75cf6cfed05128035fc4..c21f40de2be8529089617b89b5d654877236ce7d 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -281,9 +281,17 @@ release_tqe(TimerQueueEntry *node)
 static SCH_TimeoutID
 get_new_tqe_id(void)
 {
+  TimerQueueEntry *ptr;
+
+try_again:
   next_tqe_id++;
   if (!next_tqe_id)
-    next_tqe_id++;
+    goto try_again;
+
+  /* Make sure the ID isn't already used */
+  for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next)
+    if (ptr->id == next_tqe_id)
+      goto try_again;
 
   return next_tqe_id;
 }