From 2bc1b3a58302c0e550ac5894f297b9d7e3f1cc4a Mon Sep 17 00:00:00 2001 From: ru Date: Fri, 16 Sep 2005 12:49:06 +0000 Subject: [PATCH] Fix "struct ifnet" leak if attach() fails in the middle. --- sys/contrib/dev/oltr/if_oltr.c | 2 ++ sys/dev/fe/if_fe.c | 1 + sys/dev/lnc/if_lnc.c | 4 +++- sys/dev/nve/if_nve.c | 4 +++- sys/dev/patm/if_patm_attach.c | 4 +++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/contrib/dev/oltr/if_oltr.c b/sys/contrib/dev/oltr/if_oltr.c index d74663316517..ced116c585c4 100644 --- a/sys/contrib/dev/oltr/if_oltr.c +++ b/sys/contrib/dev/oltr/if_oltr.c @@ -152,12 +152,14 @@ oltr_attach(device_t dev) RF_ACTIVE | RF_SHAREABLE : RF_ACTIVE); if (sc->irq_res == NULL) { device_printf(dev, "couldn't map interrupt\n"); + if_free(ifp); return (-1); } if (bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, oltr_intr, sc, &sc-> oltr_intrhand)) { device_printf(dev, "couldn't setup interrupt\n"); bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res); + if_free(ifp); return (-1); } diff --git a/sys/dev/fe/if_fe.c b/sys/dev/fe/if_fe.c index ce5b57aaf764..0bc11979da1d 100644 --- a/sys/dev/fe/if_fe.c +++ b/sys/dev/fe/if_fe.c @@ -743,6 +743,7 @@ fe_attach (device_t dev) error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, fe_intr, sc, &sc->irq_handle); if (error) { + if_free(ifp); fe_release_resource(dev); return ENXIO; } diff --git a/sys/dev/lnc/if_lnc.c b/sys/dev/lnc/if_lnc.c index ca7f8c0998fc..1d26ad67522c 100644 --- a/sys/dev/lnc/if_lnc.c +++ b/sys/dev/lnc/if_lnc.c @@ -212,6 +212,9 @@ lnc_release_resources(device_t dev) } bus_dma_tag_destroy(sc->dmat); } + + if (sc->ifp) + if_free(sc->ifp); } /* @@ -897,7 +900,6 @@ lnc_detach_common(device_t dev) { int s = splimp(); ether_ifdetach(sc->ifp); - if_free(sc->ifp); lnc_stop(sc); lnc_release_resources(dev); diff --git a/sys/dev/nve/if_nve.c b/sys/dev/nve/if_nve.c index a04d8fce1db6..0d8267a9b154 100644 --- a/sys/dev/nve/if_nve.c +++ b/sys/dev/nve/if_nve.c @@ -560,9 +560,11 @@ nve_detach(device_t dev) if (device_is_attached(dev)) { nve_stop(sc); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); + if (sc->miibus) device_delete_child(dev, sc->miibus); bus_generic_detach(dev); diff --git a/sys/dev/patm/if_patm_attach.c b/sys/dev/patm/if_patm_attach.c index 884f16cc3ca9..0402d62ba250 100644 --- a/sys/dev/patm/if_patm_attach.c +++ b/sys/dev/patm/if_patm_attach.c @@ -477,7 +477,6 @@ patm_detach(device_t dev) mtx_unlock(&sc->mtx); atm_ifdetach(sc->ifp); - if_free(sc->ifp); patm_destroy(sc); @@ -562,6 +561,9 @@ patm_destroy(struct patm_softc *sc) cv_destroy(&sc->vcc_cv); mtx_destroy(&sc->tst_lock); mtx_destroy(&sc->mtx); + + if (sc->ifp != NULL) + if_free(sc->ifp); } /*