Page MenuHomeFreeBSD

Fix a memory leak in fdread
ClosedPublic

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

Details

Summary

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

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

Event Timeline

trix_juniper.net retitled this revision from to Fix a memory leak in fdread.
trix_juniper.net updated this object.
trix_juniper.net edited the test plan for this revision. (Show Details)
trix_juniper.net added reviewers: stevek, araujo.
trix_juniper.net 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?

Best,

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,
Tom

This revision was automatically updated to reflect the committed changes.