From fead0681ed4fa30c5daddc6df7e166f75d6616a9 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Fri, 16 Sep 2005 12:49:06 +0000 Subject: Fix "struct ifnet" leak if attach() fails in the middle. --- 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 +++- 4 files changed, 10 insertions(+), 3 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/fe/if_fe.c b/sys/dev/fe/if_fe.c index ce5b57aaf764c..0bc11979da1d2 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 ca7f8c0998fca..1d26ad67522ca 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 a04d8fce1db67..0d8267a9b1541 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 884f16cc3ca9f..0402d62ba2500 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); } /* -- cgit v1.3