[Bug locale/25770] New: newlocale memory leak in LOCPATH parsing

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug locale/25770] New: newlocale memory leak in LOCPATH parsing

Sourceware - glibc-bugs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=25770

            Bug ID: 25770
           Summary: newlocale memory leak in LOCPATH parsing
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: locale
          Assignee: unassigned at sourceware dot org
          Reporter: fweimer at redhat dot com
  Target Milestone: ---

Originally reported here:

https://github.com/valhalla/valhalla/pull/2296#issuecomment-608304654

Reproducer:

#include <locale.h>
int main() {
  freelocale(newlocale(LC_ALL, "sv_SE.UTF-8", 0));
  return 0;
}

The allocation created by __argz_add_sep in locale/newlocale.c is never freed:

  /* We perhaps really have to load some data.  So we determine the
     path in which to look for the data now.  The environment variable
     `LOCPATH' must only be used when the binary has no SUID or SGID
     bit set.  If using the default path, we tell _nl_find_locale
     by passing null and it can check the canonical locale archive.  */
  locale_path = NULL;
  locale_path_len = 0;

  locpath_var = getenv ("LOCPATH");
  if (locpath_var != NULL && locpath_var[0] != '\0')
    {
      if (__argz_create_sep (locpath_var, ':',
                             &locale_path, &locale_path_len) != 0)
        return NULL;

      if (__argz_add_sep (&locale_path, &locale_path_len,
                          _nl_default_locale_path, ':') != 0)
        return NULL;
    }

It's not a global variable, either, so it's an unbounded leak.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug locale/25770] newlocale memory leak in LOCPATH parsing and on error paths

Sourceware - glibc-bugs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=25770

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|newlocale memory leak in    |newlocale memory leak in
                   |LOCPATH parsing             |LOCPATH parsing and on
                   |                            |error paths

--- Comment #1 from Florian Weimer <fweimer at redhat dot com> ---
There are other memory leaks because the ERROR_RETURN macro does not free
allocations.

--
You are receiving this mail because:
You are on the CC list for the bug.