[Bug 242727] MII device leaks memory on detach

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Dec 19 15:31:42 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242727

            Bug ID: 242727
           Summary: MII device leaks memory on detach
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs at FreeBSD.org
          Reporter: ghuckriede at blackberry.com

Created attachment 210065
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=210065&action=edit
patch

Overview:
The 'args' and 'ivars' malloc()s do not have associated free()s.  See lines 397
and 488 of
https://svnweb.freebsd.org/base/head/sys/dev/mii/mii.c?annotate=326255.

Here is a proposed fix for this.  

The 'ivars' leak is simple to fix.  Just adding a free in the miibus_detach()
solved the issue.

The 'args' leak is a little more complicated.  This is malloc()ed for each phy
on the bus "child".  There is currently no detach function for the child. 
Added miibus_child_detached() to free the 'args'. 


Steps to Reproduce:
Attach and detach a module with mii devices.  Observe leaks.
# devinfo -v | grep re0
            re0 pnpinfo vendor=0x10ec device=0x8168 subvendor=0x10ec
subdevice=0x0123 class=0x020000 at slot=0 function=0 dbsf=pci0:3:0:0
handle=\_SB_.PCI0.RP02.PXSX
# 
# devctl detach pci0:3:0:0
#
# vmstat -m | grep devbuf
       devbuf 34770 70136K       -    35686 
16,32,64,128,256,512,1024,2048,4096,8192,65536
# devctl attach pci0:3:0:0 
# vmstat -m | grep devbuf
       devbuf 35307 70188K       -    36223 
16,32,64,128,256,512,1024,2048,4096,8192,65536
# devctl detach pci0:3:0:0
# vmstat -m | grep devbuf
       devbuf 34779 70122K       -    36223 
16,32,64,128,256,512,1024,2048,4096,8192,65536
# 


Actual Results: 
're' LEAKED 9 times of type 'devbuf' (M_DEVBUF).  2 of these leaks are from the
'mii' device.


Expected Results:
Not to leak (or in the 're' case leak less).


Build Date & Hardware:
HEADr355854 on amd64 target with any hardware with mii device(s)

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list