Fix memory leak when there are no network interfaces or an error occurs.

This commit is contained in:
Todd C. Miller
2019-02-02 13:55:30 -07:00
parent c1d934894d
commit 3788c65483

View File

@@ -149,12 +149,13 @@ get_net_ifs(char **addrinfo)
} }
} }
if (num_interfaces == 0) if (num_interfaces == 0)
debug_return_int(0); goto done;
ailen = num_interfaces * 2 * INET6_ADDRSTRLEN; ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;
if ((cp = malloc(ailen)) == NULL) { if ((cp = malloc(ailen)) == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory"); "unable to allocate memory");
debug_return_int(-1); num_interfaces = -1;
goto done;
} }
*addrinfo = cp; *addrinfo = cp;