Author: theraven
Date: Mon Jun 11 14:02:02 2012
New Revision: 236889
URL: http://svn.freebsd.org/changeset/base/236889

Log:
  Fix a leak when setting the global character locale to "C" from something 
else.
  
  Reported by:  mm

Modified:
  head/lib/libc/locale/setrunelocale.c

Modified: head/lib/libc/locale/setrunelocale.c
==============================================================================
--- head/lib/libc/locale/setrunelocale.c        Mon Jun 11 13:17:45 2012        
(r236888)
+++ head/lib/libc/locale/setrunelocale.c        Mon Jun 11 14:02:02 2012        
(r236889)
@@ -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));
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to