]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: free timer blocks on exit
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 12 Apr 2023 14:48:36 +0000 (16:48 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Apr 2023 14:22:50 +0000 (16:22 +0200)
Save pointers to allocated timer blocks and free them on exit. This
fixes the long-standing annoying "possibly lost" leak reported by
valgrind.

sched.c

diff --git a/sched.c b/sched.c
index 1f5ebe410b0cdafea8c52424677fa87a3d6849b0..1505dc3a2e1b45d19a9570ea6c7e858f177f8c13 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -104,7 +104,10 @@ static unsigned long n_timer_queue_entries;
 static SCH_TimeoutID next_tqe_id;
 
 /* Pointer to head of free list */
-static TimerQueueEntry *tqe_free_list = NULL;
+static TimerQueueEntry *tqe_free_list;
+
+/* Array of all allocated tqe blocks to be freed in finalisation */
+static ARR_Instance tqe_blocks;
 
 /* Timestamp when was last timeout dispatched for each class */
 static struct timespec last_class_dispatch[SCH_NumberOfClasses];
@@ -133,6 +136,8 @@ SCH_Initialise(void)
 
   n_timer_queue_entries = 0;
   next_tqe_id = 0;
+  tqe_free_list = NULL;
+  tqe_blocks = ARR_CreateInstance(sizeof (TimerQueueEntry *));
 
   timer_queue.next = &timer_queue;
   timer_queue.prev = &timer_queue;
@@ -154,8 +159,14 @@ SCH_Initialise(void)
 
 void
 SCH_Finalise(void) {
+  unsigned int i;
+
   ARR_DestroyInstance(file_handlers);
 
+  for (i = 0; i < ARR_GetSize(tqe_blocks); i++)
+    Free(*(TimerQueueEntry **)ARR_GetElement(tqe_blocks, i));
+  ARR_DestroyInstance(tqe_blocks);
+
   LCL_RemoveParameterChangeHandler(handle_slew, NULL);
 
   initialised = 0;
@@ -281,6 +292,7 @@ allocate_tqe(void)
     }
     new_block[0].next = NULL;
     tqe_free_list = &(new_block[TQE_ALLOC_QUANTUM - 1]);
+    ARR_AppendElement(tqe_blocks, &new_block);
   }
 
   result = tqe_free_list;