From owner-svn-src-all@FreeBSD.ORG Thu Jun 14 18:16:36 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3183A106564A; Thu, 14 Jun 2012 18:16:36 +0000 (UTC) (envelope-from mm@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 1BE8B8FC0C; Thu, 14 Jun 2012 18:16:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5EIGZQG010792; Thu, 14 Jun 2012 18:16:35 GMT (envelope-from mm@svn.freebsd.org) Received: (from mm@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5EIGZaX010790; Thu, 14 Jun 2012 18:16:35 GMT (envelope-from mm@svn.freebsd.org) Message-Id: <201206141816.q5EIGZaX010790@svn.freebsd.org> From: Martin Matuska Date: Thu, 14 Jun 2012 18:16:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237088 - stable/9/lib/libc/locale X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jun 2012 18:16:36 -0000 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));