cmd: lwip: sntp: fix netif leak when ntpserverip is unset

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@gmail.com>
Reviewed-by: Jerome Forissier <jerome.forissier@arm.com>
This commit is contained in:
Naveen Kumar Chaudhary
2026-07-23 17:05:20 +02:00
committed by Jerome Forissier
parent 02154ba036
commit 2e7e0dbb15
+1
View File
@@ -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;
}
}