Page MenuHomeFreeBSD

newlocale(3): Fix a memory leak.

Authored by markj on Sep 22 2020, 4:45 PM.
Referenced Files
Unknown Object (File)
Sun, Nov 19, 2:12 PM
Unknown Object (File)
Oct 29 2023, 11:57 PM
Unknown Object (File)
Oct 29 2023, 11:57 PM
Unknown Object (File)
Oct 29 2023, 11:57 PM
Unknown Object (File)
Oct 29 2023, 11:44 PM
Unknown Object (File)
Oct 13 2023, 2:14 AM
Unknown Object (File)
Sep 22 2023, 7:54 AM
Unknown Object (File)
Jul 9 2023, 8:40 PM



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

rS FreeBSD src repository - subversion
Lint Not Applicable
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.Oct 2 2020, 6:36 PM
This revision was automatically updated to reflect the committed changes.