summary refs log tree commit diff
path: root/locale
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-12-31 22:46:53 +0000
committerUlrich Drepper <drepper@redhat.com>2003-12-31 22:46:53 +0000
commita31f867a42e8dd7a92e58f70b73366e0a3677f57 (patch)
tree3d121d1903b77603a770852988ad4c3e734f8699 /locale
parent520ec963af2e012caa5609ad2fac041f6e7af6d7 (diff)
downloadglibc-a31f867a42e8dd7a92e58f70b73366e0a3677f57.tar.gz
glibc-a31f867a42e8dd7a92e58f70b73366e0a3677f57.tar.xz
glibc-a31f867a42e8dd7a92e58f70b73366e0a3677f57.zip
Update.
	* locale/setlocale.c (setlocale): Avoid duplicating locale names
	if we can reuse old strings.
Diffstat (limited to 'locale')
-rw-r--r--locale/setlocale.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 9f6e96439b..d012d0265f 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -322,17 +322,25 @@ setlocale (int category, const char *locale)
 		break;
 	      }
 
-	    /* We must not simply free a global locale since we have no
-	       control over the usage.  So we mark it as un-deletable.  */
+	    /* We must not simply free a global locale since we have
+	       no control over the usage.  So we mark it as
+	       un-deletable.  And yes, the 'if' is needed, the data
+	       might be in read-only memory.  */
 	    if (newdata[category]->usage_count != UNDELETABLE)
 	      newdata[category]->usage_count = UNDELETABLE;
 
 	    /* Make a copy of locale name.  */
 	    if (newnames[category] != _nl_C_name)
 	      {
-		newnames[category] = __strdup (newnames[category]);
-		if (newnames[category] == NULL)
-		  break;
+		if (strcmp (newnames[category],
+			    _nl_global_locale.__names[category]) == 0)
+		  newnames[category] = _nl_global_locale.__names[category];
+		else
+		  {
+		    newnames[category] = __strdup (newnames[category]);
+		    if (newnames[category] == NULL)
+		      break;
+		  }
 	      }
 	  }
 
@@ -356,7 +364,8 @@ setlocale (int category, const char *locale)
 	}
       else
 	for (++category; category < __LC_LAST; ++category)
-	  if (category != LC_ALL && newnames[category] != _nl_C_name)
+	  if (category != LC_ALL && newnames[category] != _nl_C_name
+	      && newnames[category] != _nl_global_locale.__names[category])
 	    free ((char *) newnames[category]);
 
       /* Critical section left.  */