[PATCH] cmd: lwip: sntp: fix netif leak when ntpserverip is unset

Naveen Kumar Chaudhary naveen.osdev at gmail.com
Fri Jul 10 17:20:40 CEST 2026


sntp_loop() allocates a netif via net_lwip_new_netif() and normally
releases it with net_lwip_remove_netif() before returning. The error
path taken when no explicit server IP is passed and ntp_server_known()
is false returns -1 directly without freeing the netif, leaking the
lwIP netif structure (and its associated state) on every failed
invocation of the sntp command.

Call net_lwip_remove_netif(netif) before returning on this path so it
matches the other exits.

Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev at gmail.com>
---
 cmd/lwip/sntp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cmd/lwip/sntp.c b/cmd/lwip/sntp.c
index 608345c873b..a3659c73ce1 100644
--- a/cmd/lwip/sntp.c
+++ b/cmd/lwip/sntp.c
@@ -71,6 +71,7 @@ static int sntp_loop(struct udevice *udev, ip_addr_t *srvip)
 	} else {
 		if (!ntp_server_known()) {
 			log_err("error: ntpserverip not set\n");
+			net_lwip_remove_netif(netif);
 			return -1;
 		}
 	}
-- 
2.43.0



More information about the U-Boot mailing list