From 28f251955568994a739f42c4976d5aef3095a227 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 30 Oct 2025 19:10:49 +0100 Subject: [PATCH] Fix crash in NTP error handling code Signed-off-by: Dominik --- src/ntp/client.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ntp/client.c b/src/ntp/client.c index 79b80ec4..9be9d7da 100644 --- a/src/ntp/client.c +++ b/src/ntp/client.c @@ -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