@@ -494,7 +494,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
494494 }
495495 errbuf [sizeof (errbuf ) - 1 ] = '\0' ;
496496 log_ntp_message (true, false, errbuf );
497- freeaddrinfo (saddr );
497+ if (saddr != NULL )
498+ freeaddrinfo (saddr );
498499 return false;
499500 }
500501
@@ -503,7 +504,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
503504 if (ntp == NULL )
504505 {
505506 log_err ("Cannot allocate memory for NTP client" );
506- freeaddrinfo (saddr );
507+ if (saddr != NULL )
508+ freeaddrinfo (saddr );
507509 return false;
508510 }
509511
@@ -520,7 +522,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
520522 {
521523 close (s );
522524 free (ntp );
523- freeaddrinfo (saddr );
525+ if (saddr != NULL )
526+ freeaddrinfo (saddr );
524527 return false;
525528 }
526529 // Get reply
@@ -543,7 +546,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
543546 printf ("\n" );
544547
545548 // Free allocated memory
546- freeaddrinfo (saddr );
549+ if (saddr != NULL )
550+ freeaddrinfo (saddr );
547551 saddr = NULL ;
548552
549553 // Compute average and standard deviation
@@ -764,9 +768,15 @@ bool ntp_start_sync_thread(pthread_attr_t *attr)
764768 }
765769 // Return early if a clock disciplining NTP client is detected
766770 // Checks chrony, the ntp family (ntp, ntpsec and openntpd), and ntpd-rs
767- if (search_proc ("chronyd" ) > 0 || search_proc ("ntpd" ) > 0 || search_proc ("ntp-daemon" ) > 0 )
771+ const int chronyd_found = search_proc ("chronyd" );
772+ const int ntpd_found = search_proc ("ntpd" );
773+ const int ntp_daemon_found = search_proc ("ntp-daemon" );
774+ if (chronyd_found > 0 || ntpd_found > 0 || ntp_daemon_found > 0 )
768775 {
769- log_info ("Clock disciplining NTP client detected, not starting embedded NTP client/server" );
776+ log_info ("Clock disciplining NTP client detected ( %s%s%s), not starting embedded NTP client/server" ,
777+ chronyd_found > 0 ? "chronyd " : "" ,
778+ ntpd_found > 0 ? "ntpd " : "" ,
779+ ntp_daemon_found > 0 ? "ntp-daemon " : "" );
770780 return false;
771781 }
772782
0 commit comments