ok?
Index: net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.584
diff -u -p -u -1 -0 -r1.584 if.c
--- net/if.c 4 Jun 2019 23:06:34 -0000 1.584
+++ net/if.c 10 Jun 2019 16:46:10 -0000
@@ -462,22 +462,21 @@ if_alloc_sadl(struct ifnet *ifp)
{
unsigned int socksize;
int namelen, masklen;
struct sockaddr_dl *sdl;
/*
* If the interface already has a link name, release it
* now. This is useful for interfaces that can change
* link types, and thus switch link names often.
*/
- if (ifp->if_sadl != NULL)
- if_free_sadl(ifp);
+ if_free_sadl(ifp);
namelen = strlen(ifp->if_xname);
masklen = offsetof(struct sockaddr_dl, sdl_data[0]) + namelen;
socksize = masklen + ifp->if_addrlen;
#define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
if (socksize < sizeof(*sdl))
socksize = sizeof(*sdl);
socksize = ROUNDUP(socksize);
sdl = malloc(socksize, M_IFADDR, M_WAITOK|M_ZERO);
sdl->sdl_len = socksize;
@@ -491,21 +490,24 @@ if_alloc_sadl(struct ifnet *ifp)
}
/*
* Free the link level name for the specified interface. This is
* a detach helper. This is called from if_detach() or from
* link layer type specific detach functions.
*/
void
if_free_sadl(struct ifnet *ifp)
{
- free(ifp->if_sadl, M_IFADDR, 0);
+ if (ifp->if_sadl == NULL)
+ return;
+
+ free(ifp->if_sadl, M_IFADDR, ifp->if_sadl->sdl_len);
ifp->if_sadl = NULL;
}
void
if_attachdomain(struct ifnet *ifp)
{
struct domain *dp;
int i, s;
s = splnet();
@@ -1127,23 +1129,23 @@ if_detach(struct ifnet *ifp)
#ifdef DIAGNOSTIC
printf("%s: address list non empty\n", ifp->if_xname);
#endif
while ((ifa = TAILQ_FIRST(&ifp->if_addrlist)) != NULL) {
ifa_del(ifp, ifa);
ifa->ifa_ifp = NULL;
ifafree(ifa);
}
}
- free(ifp->if_addrhooks, M_TEMP, 0);
- free(ifp->if_linkstatehooks, M_TEMP, 0);
- free(ifp->if_detachhooks, M_TEMP, 0);
+ free(ifp->if_addrhooks, M_TEMP, sizeof(*ifp->if_addrhooks));
+ free(ifp->if_linkstatehooks, M_TEMP, sizeof(*ifp->if_linkstatehooks));
+ free(ifp->if_detachhooks, M_TEMP, sizeof(*ifp->if_detachhooks));
for (i = 0; (dp = domains[i]) != NULL; i++) {
if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
(*dp->dom_ifdetach)(ifp,
ifp->if_afdata[dp->dom_family]);
}
/* Announce that the interface is gone. */
rtm_ifannounce(ifp, IFAN_DEPARTURE);
splx(s);