svn commit: r237088 - stable/9/lib/libc/locale
Martin Matuska
mm at FreeBSD.org
Thu Jun 14 18:16:36 UTC 2012
Author: mm
Date: Thu Jun 14 18:16:35 2012
New Revision: 237088
URL: http://svn.freebsd.org/changeset/base/237088
Log:
MFC r236889 (theraven):
Fix a leak when setting the global character locale to "C" from something
else.
Reported by: mm (myself)
Approved by: theraven (IRC)
Modified:
stable/9/lib/libc/locale/setrunelocale.c
Directory Properties:
stable/9/lib/libc/ (props changed)
Modified: stable/9/lib/libc/locale/setrunelocale.c
==============================================================================
--- stable/9/lib/libc/locale/setrunelocale.c Thu Jun 14 17:54:52 2012 (r237087)
+++ stable/9/lib/libc/locale/setrunelocale.c Thu Jun 14 18:16:35 2012 (r237088)
@@ -89,6 +89,17 @@ const _RuneLocale *__getCurrentRuneLocal
return XLOCALE_CTYPE(__get_locale())->runes;
}
+static void free_runes(_RuneLocale *rl)
+{
+ /* FIXME: The "EUC" check here is a hideous abstraction violation. */
+ if ((rl != &_DefaultRuneLocale) && (rl)) {
+ if (strcmp(rl->__encoding, "EUC") == 0) {
+ free(rl->__variable);
+ }
+ free(rl);
+ }
+}
+
static int
__setrunelocale(struct xlocale_ctype *l, const char *encoding)
{
@@ -102,6 +113,7 @@ __setrunelocale(struct xlocale_ctype *l,
* The "C" and "POSIX" locale are always here.
*/
if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
+ free_runes(saved.runes);
(void) _none_init(l, (_RuneLocale*)&_DefaultRuneLocale);
return (0);
}
@@ -153,13 +165,7 @@ __setrunelocale(struct xlocale_ctype *l,
if (ret == 0) {
/* Free the old runes if it exists. */
- /* FIXME: The "EUC" check here is a hideous abstraction violation. */
- if ((saved.runes != &_DefaultRuneLocale) && (saved.runes)) {
- if (strcmp(saved.runes->__encoding, "EUC") == 0) {
- free(saved.runes->__variable);
- }
- free(saved.runes);
- }
+ free_runes(saved.runes);
} else {
/* Restore the saved version if this failed. */
memcpy(l, &saved, sizeof(struct xlocale_ctype));
More information about the svn-src-stable-9
mailing list