}
MALLOC(*addresses, ifmultiaddr_t*, sizeof(ifmultiaddr_t) * (cmax + 1), M_TEMP, M_NOWAIT);
- if (*addresses == NULL) return ENOMEM;
+ if (*addresses == NULL) {
+ if (lock) ifnet_lock_done(interface);
+ return ENOMEM;
+ }
LIST_FOREACH(addr, &interface->if_multiaddrs, ifma_link)
{
ifnet_head_lock_shared();
TAILQ_FOREACH(ifp, &ifnet, if_link)
{
- struct sockaddr_dl *ll_addr =
- (struct sockaddr_dl *)ifnet_addrs[ifp->if_index - 1]->ifa_addr;
+ struct ifaddr *ifa = ifnet_addrs[ifp->if_index - 1];
+ struct sockaddr_dl *ll_addr;
+
+ if (!ifa || !ifa->ifa_addr)
+ continue;
+
+ ll_addr = (struct sockaddr_dl *)ifa->ifa_addr;
+
if ((ifp->if_eflags & IFEF_DETACHING) == 0 &&
namelen == ll_addr->sdl_nlen &&
(strncmp(ll_addr->sdl_data, ifname, ll_addr->sdl_nlen) == 0))