Date: Mon, 22 Nov 2004 16:44:57 -0500 From: John Baldwin <jhb@FreeBSD.org> To: freebsd-current@FreeBSD.org Cc: FreeBSD current mailing list <current@FreeBSD.org> Subject: Re: mem leak in mii ? Message-ID: <200411221644.57047.jhb@FreeBSD.org> In-Reply-To: <Pine.BSF.4.53.0411192340590.42526@e0-0.zab2.int.zabbadoz.net> References: <Pine.BSF.4.53.0411192340590.42526@e0-0.zab2.int.zabbadoz.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 19 November 2004 06:49 pm, Bjoern A. Zeeb wrote:
> Hi,
>
> in sys/dev/mii/mii.c there are two calls to malloc for ivars;
> see for example mii_phy_probe:
>
> v = malloc(sizeof(vm_offset_t) * 2, M_DEVBUF, M_NOWAIT);
> if (v == 0) {
> return (ENOMEM);
> }
> v[0] = ifmedia_upd;
> v[1] = ifmedia_sts;
> *child = device_add_child(dev, "miibus", -1);
> device_set_ivars(*child, v);
>
> Where is the free for this malloc ? I cannot find it.
>
> analogous: miibus_probe ?
It's a leak. It should be free'd when the miibus device is destroyed. Here's
a possible fix:
Index: dev/mii/mii.c
===================================================================
RCS file: /usr/cvs/src/sys/dev/mii/mii.c,v
retrieving revision 1.20
diff -u -r1.20 mii.c
--- dev/mii/mii.c 15 Aug 2004 06:24:40 -0000 1.20
+++ dev/mii/mii.c 22 Nov 2004 21:43:40 -0000
@@ -186,11 +186,15 @@
device_t dev;
{
struct mii_data *mii;
+ void **v;
bus_generic_detach(dev);
mii = device_get_softc(dev);
ifmedia_removeall(&mii->mii_media);
mii->mii_ifp = NULL;
+ v = device_get_ivars(dev);
+ device_set_ivars(dev, NULL);
+ free(v, M_DEVBUF);
return(0);
}
@@ -325,6 +329,7 @@
if (i == MII_NPHY) {
device_delete_child(dev, *child);
+ free(v, M_DEVBUF);
*child = NULL;
return(ENXIO);
}
--
John Baldwin <jhb@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" = http://www.FreeBSD.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411221644.57047.jhb>
