Page MenuHomeFreeBSD

Fix a memory leak in telnetd
ClosedPublic

Authored by trix_juniper.net on Feb 20 2017, 3:55 PM.

Details

Summary

Fix memory leak in edithost

The problem is that when the parameter 'pat' is null, the function locally allocates a NULL string but never frees it.

Instead of tracking the local alloc, it is noted that the while(*pat) never enters when there is a local alloc.
So instead of doing the local alloc, check that 'pat' is null before the while(*pat) loop.

Test Plan

Run clang's static analyzer, scan-build, before to find the problem; run scan-build after to verify 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 telnetd.
trix_juniper.net updated this object.
trix_juniper.net edited the test plan for this revision. (Show Details)
trix_juniper.net added reviewers: stevek, markm.
trix_juniper.net set the repository for this revision to rS FreeBSD src repository.
markm accepted this revision.Feb 24 2017, 6:34 PM
markm edited edge metadata.

Looks good to me.

contrib/telnet/telnetd/utility.c
364 ↗(On Diff #25424)

Oooh, yuk. Well spotted.

This revision is now accepted and ready to land.Feb 24 2017, 6:34 PM

Credit goes to clang¹s static analyzer scan-build.
I only read the reports it generated.
Tom

This revision was automatically updated to reflect the committed changes.