mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
if_vxlan(4): Plug a memory leak
On clone creating, either failure from vxlan_set_user_config() or
ifc_copyin() will result in leaking previous allocated counters.
Since counter_u64_alloc(M_WAITOK) never fails, make vxlan_stats_alloc()
void and move the allocation for counters below checking ifd->params to
avoid memory leak.
Reviewed by: kp, glebius
Fixes: b092fd6c97 if_vxlan(4): add support for hardware assisted checksumming, TSO, and RSS
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D45822
This commit is contained in:
parent
d6963b9ed3
commit
087f5e08ab
1 changed files with 6 additions and 30 deletions
|
|
@ -367,7 +367,7 @@ static bool vxlan_rcv_udp_packet(struct mbuf *, int, struct inpcb *,
|
|||
static int vxlan_input(struct vxlan_socket *, uint32_t, struct mbuf **,
|
||||
const struct sockaddr *);
|
||||
|
||||
static int vxlan_stats_alloc(struct vxlan_softc *);
|
||||
static void vxlan_stats_alloc(struct vxlan_softc *);
|
||||
static void vxlan_stats_free(struct vxlan_softc *);
|
||||
static void vxlan_set_default_config(struct vxlan_softc *);
|
||||
static int vxlan_set_user_config(struct vxlan_softc *,
|
||||
|
|
@ -2923,27 +2923,14 @@ out:
|
|||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
vxlan_stats_alloc(struct vxlan_softc *sc)
|
||||
{
|
||||
struct vxlan_statistics *stats = &sc->vxl_stats;
|
||||
|
||||
stats->txcsum = counter_u64_alloc(M_WAITOK);
|
||||
if (stats->txcsum == NULL)
|
||||
goto failed;
|
||||
|
||||
stats->tso = counter_u64_alloc(M_WAITOK);
|
||||
if (stats->tso == NULL)
|
||||
goto failed;
|
||||
|
||||
stats->rxcsum = counter_u64_alloc(M_WAITOK);
|
||||
if (stats->rxcsum == NULL)
|
||||
goto failed;
|
||||
|
||||
return (0);
|
||||
failed:
|
||||
vxlan_stats_free(sc);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -2951,18 +2938,9 @@ vxlan_stats_free(struct vxlan_softc *sc)
|
|||
{
|
||||
struct vxlan_statistics *stats = &sc->vxl_stats;
|
||||
|
||||
if (stats->txcsum != NULL) {
|
||||
counter_u64_free(stats->txcsum);
|
||||
stats->txcsum = NULL;
|
||||
}
|
||||
if (stats->tso != NULL) {
|
||||
counter_u64_free(stats->tso);
|
||||
stats->tso = NULL;
|
||||
}
|
||||
if (stats->rxcsum != NULL) {
|
||||
counter_u64_free(stats->rxcsum);
|
||||
stats->rxcsum = NULL;
|
||||
}
|
||||
counter_u64_free(stats->txcsum);
|
||||
counter_u64_free(stats->tso);
|
||||
counter_u64_free(stats->rxcsum);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -3233,9 +3211,6 @@ vxlan_clone_create(struct if_clone *ifc, char *name, size_t len,
|
|||
sc->vxl_unit = ifd->unit;
|
||||
sc->vxl_fibnum = curthread->td_proc->p_fibnum;
|
||||
vxlan_set_default_config(sc);
|
||||
error = vxlan_stats_alloc(sc);
|
||||
if (error != 0)
|
||||
goto fail;
|
||||
|
||||
if (ifd->params != NULL) {
|
||||
error = ifc_copyin(ifd, &vxlp, sizeof(vxlp));
|
||||
|
|
@ -3247,6 +3222,7 @@ vxlan_clone_create(struct if_clone *ifc, char *name, size_t len,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
vxlan_stats_alloc(sc);
|
||||
ifp = if_alloc(IFT_ETHER);
|
||||
sc->vxl_ifp = ifp;
|
||||
rm_init(&sc->vxl_lock, "vxlanrm");
|
||||
|
|
|
|||
Loading…
Reference in a new issue