Created attachment 240901 [details] Fix of memory leak when mii_attach() fails When the PHY attach fails, the allocated miibus->softc from mii_attach() -> device_set_driver() is not free. There is a memory leak for the "bus-sc" memory. A proposed fix is attached.
this looks like a trivial enough patch to submit via GitHub: https://docs.freebsd.org/en/articles/contributing/
from IRC: 16:31 <kevans91_> meeena: mii_attach doesn't appear to allocate the softc except by device_* API that does it implicitly, why isn't this cleaned up with device_delete_child(), I wonder? 16:33 <kevans91_> it doesn't seem to claim the softc to prevent it from being cleaned up elsewhere
(In reply to Mina Galić from comment #2) Thanks for the suggestions. I agree that it would be better to clean up the softc in device_delete_child(). Since changing the device_delete_child() would have an impact on many devices and the softc will be allocated if the "miibus" input parameter of mii_attach() is null, I only change it in the mii_attach() for minimal impact of other components. It would be better that Freebsd can re-investigate the memory allocation issues using device_*() APIs.