Date: Thu, 14 Jun 2012 18:16:35 +0000 (UTC) From: Martin Matuska <mm@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r237088 - stable/9/lib/libc/locale Message-ID: <201206141816.q5EIGZaX010790@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206141816.q5EIGZaX010790>