git: e1c53fc8e154 - stable/13 - xlocale.c: only call init_key() when locale was successfully allocated

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 09 Feb 2022 00:48:08 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=e1c53fc8e15491d03641736e07c743fcb4324b2f

commit e1c53fc8e15491d03641736e07c743fcb4324b2f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-02-02 17:25:45 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-02-09 00:42:45 +0000

    xlocale.c: only call init_key() when locale was successfully allocated
    
    (cherry picked from commit 7bf532c9d447bfdf03f42a5c5092fb74740722b2)
---
 lib/libc/locale/xlocale.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/libc/locale/xlocale.c b/lib/libc/locale/xlocale.c
index 467d6e6e5aee..4bddc43c086b 100644
--- a/lib/libc/locale/xlocale.c
+++ b/lib/libc/locale/xlocale.c
@@ -257,13 +257,13 @@ newlocale(int mask, const char *locale, locale_t base)
 	int useenv = 0;
 	int success = 1;
 
-	_once(&once_control, init_key);
-
 	locale_t new = alloc_locale();
 	if (NULL == new) {
 		return (NULL);
 	}
 
+	_once(&once_control, init_key);
+
 	orig_base = base;
 	FIX_LOCALE(base);
 	copyflags(new, base);
@@ -312,12 +312,12 @@ duplocale(locale_t base)
 	locale_t new = alloc_locale();
 	int type;
 
-	_once(&once_control, init_key);
-
 	if (NULL == new) {
 		return (NULL);
 	}
 	
+	_once(&once_control, init_key);
+
 	FIX_LOCALE(base);
 	copyflags(new, base);