xlocale.c: only call init_key() when locale was successfully allocated

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D34140
This commit is contained in:
Konstantin Belousov 2022-02-02 19:25:45 +02:00
parent b68522308d
commit 7bf532c9d4

View File

@ -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);