1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Make uenvarea thread exclusive

This commit is contained in:
Nobuyoshi Nakada 2021-02-23 20:51:02 +09:00
parent 41eb4fbf86
commit 5a4742a0b4
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -750,11 +750,14 @@ exit_handler(void)
DeleteCriticalSection(&select_mutex);
DeleteCriticalSection(&socklist_mutex);
DeleteCriticalSection(&conlist_mutex);
thread_exclusive(uenvarea) {
if (uenvarea) {
free(uenvarea);
uenvarea = NULL;
}
}
DeleteCriticalSection(&uenvarea_mutex);
}
/* License: Ruby's */
static void
@ -808,6 +811,7 @@ StartSockets(void)
InitializeCriticalSection(&select_mutex);
InitializeCriticalSection(&socklist_mutex);
InitializeCriticalSection(&conlist_mutex);
InitializeCriticalSection(&uenvarea_mutex);
atexit(exit_handler);
}
@ -5261,11 +5265,12 @@ w32_getenv(const char *name, UINT cp)
{
WCHAR *wenvarea, *wenv;
int len = strlen(name);
char *env;
char *env = NULL;
int wlen;
if (len == 0) return NULL;
thread_exclusive(uenvarea) {
if (uenvarea) {
free(uenvarea);
uenvarea = NULL;
@ -5273,20 +5278,24 @@ w32_getenv(const char *name, UINT cp)
wenvarea = GetEnvironmentStringsW();
if (!wenvarea) {
map_errno(GetLastError());
return NULL;
continue;
}
for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
wlen += lstrlenW(wenv) + 1;
uenvarea = wstr_to_mbstr(cp, wenvarea, wlen, NULL);
FreeEnvironmentStringsW(wenvarea);
if (!uenvarea)
return NULL;
continue;
for (env = uenvarea; *env; env += strlen(env) + 1)
if (strncasecmp(env, name, len) == 0 && *(env + len) == '=')
return env + len + 1;
for (env = uenvarea; *env; env += strlen(env) + 1) {
if (strncasecmp(env, name, len) == 0 && *(env + len) == '=') {
env += len + 1;
break;
}
}
}
return NULL;
return env;
}
/* License: Ruby's */