Page MenuHomeFreeBSD

Fix a memory leak in fdread

Authored by on Mar 2 2017, 4:53 AM.



fdread.c doread
Free the memory allocated to trackbuf before exiting

Test Plan

Use clang's static analyzer, scan-build, to find the problem and then to verify the problem is resolved

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline retitled this revision from to Fix a memory leak in fdread. updated this object. edited the test plan for this revision. (Show Details) added reviewers: stevek, araujo. set the repository for this revision to rS FreeBSD src repository.
araujo edited edge metadata.Mar 10 2017, 3:18 AM

Do you still have the log of analyzer before and after this patch?

I will have to reproduce these, I will send it out asap.

This is the before, the line number is a bit screwed up because i commented out my change.
The after has memory leak removed.

usr.sbin/fdread/fdread.c:134:2: warning: Value stored to 'argv' is never read

argv += optind;
^       ~~~~~~

usr.sbin/fdread/fdread.c:243:14: warning: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage

fdopts |= FDOPT_NOERROR;
~~~~~~ ^

usr.sbin/fdread/fdread.c:291:7: warning: Potential leak of memory pointed to by 'trackbuf'

if (!quiet) {

3 warnings generated.
scan-build: 3 bugs found.

araujo accepted this revision.Mar 12 2017, 5:22 AM

Looks good to me! Do you want me commit it or you have src bit?


This revision is now accepted and ready to land.Mar 12 2017, 5:22 AM

Yes, please commit. I do not have commit perms.
Thank you,

This revision was automatically updated to reflect the committed changes.