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