diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2019-06-10 16:32:52 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2019-06-10 16:32:52 +0000 |
commit | 424b3f1c2665f7876e31a61a29a4c9175c40bd09 (patch) | |
tree | 416d9c06bf918dc488f0fd5c0cadedc9246a9c25 /sys/netinet | |
parent | 2f27282b5b0424dacfaf119d3639072d35049108 (diff) |
Use mallocarray(9) & put some free(9) sizes for M_IPMOPTS allocations.
ok semarie@, visa@
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/ip_carp.c | 10 | ||||
-rw-r--r-- | sys/netinet/ip_output.c | 16 |
2 files changed, 13 insertions, 13 deletions
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 8f6d59b3953..80ce7cb4b38 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.337 2019/04/23 10:53:45 dlg Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.338 2019/06/10 16:32:51 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -814,9 +814,8 @@ carp_clone_create(struct if_clone *ifc, int unit) #ifdef INET6 sc->sc_im6o.im6o_hlim = CARP_DFLTTL; #endif /* INET6 */ - sc->sc_imo.imo_membership = (struct in_multi **)malloc( - (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, - M_WAITOK|M_ZERO); + sc->sc_imo.imo_membership = mallocarray(IP_MIN_MEMBERSHIPS, + sizeof(struct in_multi *), M_IPMOPTS, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; LIST_INIT(&sc->carp_mc_listhead); @@ -901,7 +900,8 @@ carp_clone_destroy(struct ifnet *ifp) if_detach(ifp); carp_destroy_vhosts(ifp->if_softc); refcnt_finalize(&sc->sc_refcnt, "carpdtor"); - free(sc->sc_imo.imo_membership, M_IPMOPTS, 0); + free(sc->sc_imo.imo_membership, M_IPMOPTS, + sc->sc_imo.imo_max_memberships * sizeof(struct in_multi *)); free(sc, M_DEVBUF, sizeof(*sc)); return (0); } diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index b69cebc5d0b..7bc8254d3de 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.354 2019/04/28 22:15:58 mpi Exp $ */ +/* $OpenBSD: ip_output.c,v 1.355 2019/06/10 16:32:51 mpi Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -1362,8 +1362,7 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, * allocate one and initialize to default values. */ imo = malloc(sizeof(*imo), M_IPMOPTS, M_WAITOK|M_ZERO); - immp = (struct in_multi **)malloc( - (sizeof(*immp) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, + immp = mallocarray(IP_MIN_MEMBERSHIPS, sizeof(*immp), M_IPMOPTS, M_WAITOK|M_ZERO); *imop = imo; imo->imo_ifidx = 0; @@ -1517,9 +1516,8 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, omships = imo->imo_membership; newmax = ((imo->imo_max_memberships + 1) * 2) - 1; if (newmax <= IP_MAX_MEMBERSHIPS) { - nmships = (struct in_multi **)mallocarray( - newmax, sizeof(*nmships), M_IPMOPTS, - M_NOWAIT|M_ZERO); + nmships = mallocarray(newmax, sizeof(*nmships), + M_IPMOPTS, M_NOWAIT|M_ZERO); if (nmships != NULL) { memcpy(nmships, omships, sizeof(*omships) * @@ -1623,7 +1621,8 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, imo->imo_ttl == IP_DEFAULT_MULTICAST_TTL && imo->imo_loop == IP_DEFAULT_MULTICAST_LOOP && imo->imo_num_memberships == 0) { - free(imo->imo_membership , M_IPMOPTS, 0); + free(imo->imo_membership , M_IPMOPTS, + imo->imo_max_memberships * sizeof(struct in_multi *)); free(*imop, M_IPMOPTS, sizeof(**imop)); *imop = NULL; } @@ -1688,7 +1687,8 @@ ip_freemoptions(struct ip_moptions *imo) if (imo != NULL) { for (i = 0; i < imo->imo_num_memberships; ++i) in_delmulti(imo->imo_membership[i]); - free(imo->imo_membership, M_IPMOPTS, 0); + free(imo->imo_membership, M_IPMOPTS, + imo->imo_max_memberships * sizeof(struct in_multi *)); free(imo, M_IPMOPTS, sizeof(*imo)); } } |