Page MenuHomeFreeBSD

newlocale(3): Fix a memory leak.
ClosedPublic

Authored by markj on Sep 22 2020, 4:45 PM.

Details

Summary

newlocale() optionally takes a "base" locale, from which components not
specified in the mask are inherited. POSIX says that newlocale() may
modify "base" and return it, or free "base" and return a newly allocated
locale. We are not doing either, so applications which use newlocale()
to modify an existing base locale end up leaking memory on FreeBSD.

This diff fixes the leak by releasing a reference to the base locale
before returning. This is less efficient than modifying "base"
directly, but is simpler for an initial bug fix. Also, update the man
page to clarify behaviour wrt to "base".

Test Plan

Use the test program provided with PR 249416.

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

markj requested review of this revision.Sep 22 2020, 4:45 PM
markj created this revision.
markj added a reviewer: yuripv.
markj added a subscriber: leres.
This revision was not accepted when it landed; it landed in state Needs Review.Fri, Oct 2, 6:36 PM
This revision was automatically updated to reflect the committed changes.