Merge pull request #2684 from pi-hole/fix/ntp_error_crash

Fix crash in NTP error handling code
This commit is contained in:
Dominik
2025-10-31 20:12:22 +01:00
committed by GitHub

View File

@@ -494,7 +494,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
} }
errbuf[sizeof(errbuf) - 1] = '\0'; errbuf[sizeof(errbuf) - 1] = '\0';
log_ntp_message(true, false, errbuf); log_ntp_message(true, false, errbuf);
freeaddrinfo(saddr); if(saddr != NULL)
freeaddrinfo(saddr);
return false; return false;
} }
@@ -503,7 +504,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
if(ntp == NULL) if(ntp == NULL)
{ {
log_err("Cannot allocate memory for NTP client"); log_err("Cannot allocate memory for NTP client");
freeaddrinfo(saddr); if(saddr != NULL)
freeaddrinfo(saddr);
return false; return false;
} }
@@ -520,7 +522,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
{ {
close(s); close(s);
free(ntp); free(ntp);
freeaddrinfo(saddr); if(saddr != NULL)
freeaddrinfo(saddr);
return false; return false;
} }
// Get reply // Get reply
@@ -543,7 +546,8 @@ bool ntp_client(const char *server, const bool settime, const bool print)
printf("\n"); printf("\n");
// Free allocated memory // Free allocated memory
freeaddrinfo(saddr); if(saddr != NULL)
freeaddrinfo(saddr);
saddr = NULL; saddr = NULL;
// Compute average and standard deviation // Compute average and standard deviation