Bug 125496 - [ar] [patch] free memory on ataraid module unload
Summary: [ar] [patch] free memory on ataraid module unload
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 6.2-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-11 07:10 UTC by Andrey V. Elsukov
Modified: 2015-11-10 13:45 UTC (History)
2 users (show)

See Also:


Attachments
ataraid_fix_memory_leak_on_module_unload.diff (1.07 KB, patch)
2008-07-11 07:10 UTC, Andrey V. Elsukov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey V. Elsukov 2008-07-11 07:10:00 UTC
ataraid module has subdisk pseudo-driver which attaches to ata diskis.
It calls ata_raid_read_metadata() function which allocate memory which shares
between all subdisks in RAID:

        if (!raidp[array]) {
            raidp[array] =
                (struct ar_softc *)malloc(sizeof(struct ar_softc), M_AR,
                                          M_NOWAIT | M_ZERO);
            if (!raidp[array]) {
                device_printf(parent, "failed to allocate metadata storage\n");
                goto adaptec_out;
            }
        }
(Similar code has all ata_raid_xxxx_read_meta functions)
Pointer to this memory stored in static local array ata_raid_arrays[]. 
This memory not freed when ataraid module unloads.

Attached patch adds freeing memory on module unload. Because ataraid(4)
module has two kernel modules - subdisk and ataraid, they both will be
unloaded when `kldunload ataraid`. And all subdisks will be detached.
So we can free shared memory between subdisks, but we should reset all
pointers before freeing, because ata_raid_subdisk_detach() method will be
called on module unload and this method can do access to this memory after
freeing.

I'm not 100% sure in correctness of this patch, so it needs review..
Comment 1 Andrey V. Elsukov 2008-07-11 07:15:21 UTC
Andrey V. Elsukov wrote:
> I'm not 100% sure in correctness of this patch, so it needs review..

I forgot to mention that it works for me. Without patch after unload
module system reports that 1k ar_driver-type memory leaked. After
patch this message gone. I have only one RAID configured on Intel
Matrix.

-- 
WBR, Andrey V. Elsukov
Comment 2 Enji Cooper freebsd_committer freebsd_triage 2015-11-10 13:45:23 UTC
atapicam is no more after FreeBSD 9.x. Long live atacam and friends.