]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Fix errors detected by valgrind
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 5 Nov 2008 23:48:58 +0000 (23:48 +0000)
committerRichard P. Curnow <rc@rc0.org.uk>
Wed, 5 Nov 2008 23:48:58 +0000 (23:48 +0000)
I tried running chronyd in valgrind and the result was that there are four
places where memory is not initialized. A patch fixing the errors is in the
attachment.

cmdmon.c
ntp_core.c
sourcestats.c

index e88d7c363e7bdbd09a041aa85d32037e38ae596f..819977c9330f17d2ab40a145a19899856022cd6b 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -166,7 +166,7 @@ CAM_Initialise(void)
   int port_number;
   struct sockaddr_in my_addr;
   unsigned long bind_address;
-  int on_off;
+  int on_off = 1;
 
   if (initialised) {
     CROAK("Shouldn't be initialised");
@@ -1631,11 +1631,13 @@ read_from_cmd_socket(void *anything)
   tx_message.reply = htons(RPY_NULL);
   tx_message.number = htons(1);
   tx_message.total = htons(1);
+  tx_message.pad1 = 0;
   tx_message.utoken = htonl(utoken);
   /* Set this to a default (invalid) value.  This protects against the
      token field being set to an arbitrary value if we reject the
      message, e.g. due to the host failing the access check. */
   tx_message.token = htonl(0xffffffffUL);
+  memset(&tx_message.auth, 0, sizeof(tx_message.auth));
 
   remote_ip = ntohl(where_from.sin_addr.s_addr);
   remote_port = ntohs(where_from.sin_port);
index 60d433c6b47b1c4e28a3202cbc89972ecce61c18..8dfd6cfb36f3fb6e68c4afc0769050465bb38a84 100644 (file)
@@ -300,6 +300,9 @@ create_instance(NTP_Remote_Address *remote_addr, NTP_Mode mode, SourceParameters
 
   result->tx_count = 0;
 
+  result->remote_orig.hi = 0;
+  result->remote_orig.lo = 0;
+
   result->score = 0;
 
   if (params->online) {
index 163a2ebd9127079d9734e0b544a4e1b8db9c94f4..564eb3acfbf25b9262a7d061b2b5a8e9b203d89e 100644 (file)
@@ -721,8 +721,12 @@ SST_PredictOffset(SST_Stats inst, struct timeval *when)
   if (inst->n_samples < 3) {
     /* We don't have any useful statistics, and presumably the poll
        interval is minimal.  We can't do any useful prediction other
-       than use the latest sample */
-    return inst->offsets[inst->n_samples - 1];
+       than use the latest sample or zero if we don't have any samples */
+    if (inst->n_samples > 0) {
+      return inst->offsets[inst->n_samples - 1];
+    } else {
+      return 0.0;
+    }
   } else {
     UTI_DiffTimevalsToDouble(&elapsed, when, &inst->offset_time);
     return inst->estimated_offset + elapsed * inst->estimated_frequency;