From owner-freebsd-current@FreeBSD.ORG Mon Nov 22 22:00:00 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 25CA016A4CE for ; Mon, 22 Nov 2004 22:00:00 +0000 (GMT) Received: from mail2.speakeasy.net (mail2.speakeasy.net [216.254.0.202]) by mx1.FreeBSD.org (Postfix) with ESMTP id BCF7743D2D for ; Mon, 22 Nov 2004 21:59:59 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 11288 invoked from network); 22 Nov 2004 21:59:59 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 22 Nov 2004 21:59:59 -0000 Received: from [10.50.41.235] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.12.11/8.12.11) with ESMTP id iAMLxdYi030036; Mon, 22 Nov 2004 16:59:48 -0500 (EST) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-current@FreeBSD.org Date: Mon, 22 Nov 2004 16:44:57 -0500 User-Agent: KMail/1.6.2 References: In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200411221644.57047.jhb@FreeBSD.org> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: "Bjoern A. Zeeb" cc: FreeBSD current mailing list Subject: Re: mem leak in mii ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2004 22:00:00 -0000 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 <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org