bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Memory leak in locale.c set_default_locale


From: Chet Ramey
Subject: Re: [PATCH] Memory leak in locale.c set_default_locale
Date: Thu, 8 Jun 2017 09:59:39 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

On 6/7/17 9:46 PM, dualbus wrote:

> *** /tmp/R6GbnO_locale.c      2017-06-07 20:40:25.575118629 -0500
> --- locale.c  2017-06-07 20:39:59.054419575 -0500
> ***************
> *** 85,91 ****
>     textdomain (PACKAGE);
>   
>     locale_mb_cur_max = MB_CUR_MAX;
> !   locale_utf8locale = locale_isutf8 (default_locale);
>     locale_shiftstates = mblen ((char *)NULL, 0);
>   }
>   
> --- 85,98 ----
>     textdomain (PACKAGE);
>   
>     locale_mb_cur_max = MB_CUR_MAX;
> !   locale_utf8locale = 0;
> ! #if defined (HAVE_SETLOCALE)
> !   if (default_locale)
> !     {
> !       locale_utf8locale = locale_isutf8 (default_locale);
> !       free (default_locale);
> !     }
> ! #endif /* HAVE_SETLOCALE */
>     locale_shiftstates = mblen ((char *)NULL, 0);
>   }

This is a glibc issue.  Bash keeps a copy of the default locale for its
own purposes, and copies it because the return value from setlocale() is
an opaque pointer. glibc happens to store it in malloc'd memory, but there
is no requirement that setlocale() do so, and other systems (Mac OS X) do
not.  I'm not sure why this is considered a leak, though, since glibc keeps
a handle on the memory for the current locale.

Even though glibc allocates the memory for the current locale, the man page
warns not to assume that:

"A successful call to setlocale() returns an opaque string  that  corre-
sponds to the locale set.  This string may be allocated in static storage."

Posix contains similar warning language.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]