Page MenuHomeFreeBSD

Fix a memory leak with add_mapping
ClosedPublic

Authored by trix_juniper.net on Feb 18 2017, 2:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Mar 22, 2:38 PM
Unknown Object (File)
Fri, Mar 22, 2:38 PM
Unknown Object (File)
Fri, Mar 22, 2:38 PM
Unknown Object (File)
Jan 26 2024, 11:46 PM
Unknown Object (File)
Dec 12 2023, 10:41 PM
Unknown Object (File)
Dec 5 2023, 8:08 PM
Unknown Object (File)
Oct 31 2023, 12:23 AM
Unknown Object (File)
Oct 25 2023, 9:58 AM
Subscribers

Details

Summary

The memory assigned to the local variable 'copy' is mostly freed.
The case where is can not be freed is noted with a comment.

Test Plan

Run clang's static analyzer scan-build before to find the problem. Run scan-build after to show the problem is reduced to the use of 'copy' in the badmopt: location.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

trix_juniper.net retitled this revision from to Fix a memory leak with add_mapping.
trix_juniper.net updated this object.
trix_juniper.net edited the test plan for this revision. (Show Details)
trix_juniper.net added reviewers: stevek, ed.
trix_juniper.net set the repository for this revision to rS FreeBSD src repository - subversion.
usr.bin/tset/map.c
85

I don't understand this change. What's the advantage of calling free() if you're already going to call errx()?

usr.bin/tset/map.c
178

Could you please move the call to free() closer to to the site where the variable is last used? Thanks!

moved free(copy) to last use of copy and poisoned copy after the free

ed edited edge metadata.
ed added inline comments.
usr.bin/tset/map.c
161

I think assignments like these are typically not done in our codebase, especially not for local variables. Statements like these tend to have no effect, as the compiler will optimize it out anyway.

Apart from that, it looks good!

This revision is now accepted and ready to land.Feb 20 2017, 3:27 PM
This revision was automatically updated to reflect the committed changes.