Re: mem leak in mii ?

From: John Baldwin (jhb_at_FreeBSD.org)
Date: 11/22/04

  • Next message: John Baldwin: "Re: mem leak in mii ?"
    To: freebsd-current@FreeBSD.org
    Date: Mon, 22 Nov 2004 16:44:57 -0500
    
    

    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
    _______________________________________________
    freebsd-current@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-current
    To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
    

  • Next message: John Baldwin: "Re: mem leak in mii ?"

    Relevant Pages

    • Re: pxeloader problem: BTX halted
      ... On Sunday 15 February 2004 05:54 am, Bjoern A. Zeeb wrote: ... > thing I could read on the screen (no serial console at that point) had ... To unsubscribe, ...
      (freebsd-current)
    • Re: netgraph only on i386/ia64 - why ?
      ... On Wed, 18 Aug 2004, Ruslan Ermilov wrote: ... RE>>> On Mon, 16 Aug 2004, Bjoern A. Zeeb wrote: ... To unsubscribe, ...
      (freebsd-net)
    • Re: mem leak in mii ?
      ... On Friday 19 November 2004 06:49 pm, Bjoern A. Zeeb wrote: ... > Where is the free for this malloc? ... To unsubscribe, ...
      (freebsd-current)
    • Re: Fatal trap 12 in microuptime
      ... At 04:55 07/07/2004, Bjoern A. Zeeb wrote: ... >when PXE booting I am getting this: ... To unsubscribe, ...
      (freebsd-current)
    • Re: LOR on AMD64
      ... On Saturday 20 August 2005 08:56 am, Bjoern A. Zeeb wrote: ... >> but on my machine I obtain the attached LOR instead of a panic, ... across a call to malloc() and that mallochappened to block. ...
      (freebsd-current)