intel / idxd-config

Accel-config / libaccel-config
Other
59 stars 35 forks source link

Fixing memory leak by freeing memory allocated by scandir() #47

Closed abdelrahim-hentabli closed 11 months ago

abdelrahim-hentabli commented 12 months ago

Background

According to the scandir() manual page

The scandir() function scans the directory dirp, calling filter() on each directory entry. Entries for which filter() returns nonzero are stored in strings allocated via malloc(3), sorted using qsort(3) with the comparison function compar(), and collected in array namelist which is allocated via malloc(3). If filter is NULL, all entries are selected.

Using the same syntax for freeing as found here: https://github.com/intel/idxd-config/blob/435fa62bca9bd64069f7d816eae44b7bcc63f3bb/accfg/lib/libaccfg.c#L2249-L2251

Testing

image

Output of DML with memory-sanitizer Before change: image

After change: image

ramesh-thomas commented 11 months ago

Can you merge the commits as you add the n1 variable change in one patch and then remove it in the next making that change redundant?

abdelrahim-hentabli commented 11 months ago

Can you merge the commits as you add the n1 variable change in one patch and then remove it in the next making that change redundant?

just fixed this

ramesh-thomas commented 11 months ago

Merged into pending branch.