Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Oct 2020 14:47:32 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r366971 - stable/12/lib/libc/locale
Message-ID:  <202010231447.09NElW0q037000@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Fri Oct 23 14:47:32 2020
New Revision: 366971
URL: https://svnweb.freebsd.org/changeset/base/366971

Log:
  MFC r366375:
  newlocale(3): Fix a memory leak.
  
  PR:	249416

Modified:
  stable/12/lib/libc/locale/newlocale.3
  stable/12/lib/libc/locale/xlocale.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libc/locale/newlocale.3
==============================================================================
--- stable/12/lib/libc/locale/newlocale.3	Fri Oct 23 14:25:48 2020	(r366970)
+++ stable/12/lib/libc/locale/newlocale.3	Fri Oct 23 14:47:32 2020	(r366971)
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $FreeBSD$
-.Dd September 17, 2011
+.Dd October 2, 2020
 .Dt NEWLOCALE 3
 .Os
 .Sh NAME
@@ -46,7 +46,20 @@ defines the components that the new locale will have s
 name specified in the
 .Fa locale
 parameter.
-Any other components will be inherited from
+Any components not specified in
+.Fa mask
+will be inherited from the locale referenced by
+.Fa base ,
+if
+.Fa base
+is not
+.Dv NULL .
+If the call is successful, the state of the locale referenced by
+.Fa base
+is unspecified, and it must not be accessed.
+The special locale
+.Dv LC_GLOBAL_LOCALE
+may not be specified for
 .Fa base .
 The
 .Fa mask

Modified: stable/12/lib/libc/locale/xlocale.c
==============================================================================
--- stable/12/lib/libc/locale/xlocale.c	Fri Oct 23 14:25:48 2020	(r366970)
+++ stable/12/lib/libc/locale/xlocale.c	Fri Oct 23 14:47:32 2020	(r366971)
@@ -251,6 +251,7 @@ static int dupcomponent(int type, locale_t base, local
 
 locale_t newlocale(int mask, const char *locale, locale_t base)
 {
+	locale_t orig_base;
 	int type;
 	const char *realLocale = locale;
 	int useenv = 0;
@@ -263,6 +264,7 @@ locale_t newlocale(int mask, const char *locale, local
 		return (NULL);
 	}
 
+	orig_base = base;
 	FIX_LOCALE(base);
 	copyflags(new, base);
 
@@ -297,6 +299,8 @@ locale_t newlocale(int mask, const char *locale, local
 	if (0 == success) {
 		xlocale_release(new);
 		new = NULL;
+	} else if (base == orig_base) {
+		xlocale_release(base);
 	}
 
 	return (new);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010231447.09NElW0q037000>