From e1c705b2657dd5b93c4dd2683b9032a656396571 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 26 Apr 2016 15:45:00 +0200 Subject: [PATCH 2/3] Fix the load race in pgwin32_putenv() (and open the unload race). Before, any CRT first loaded after the first call to pgwin32_putenv() would be frozen out because the "not found" result was cached for the lifetime of the process. This fixes the "load" race and makes it much more likely that an "unload" race happens instead, where a CRT is loaded, noticed and cached, then unloaded, and then the next call to pgwin32_putenv() crashes. --- src/port/win32env.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/port/win32env.c b/src/port/win32env.c index fd6762e..9afc31f 100644 --- a/src/port/win32env.c +++ b/src/port/win32env.c @@ -73,15 +73,10 @@ pgwin32_putenv(const char *envval) { if (rtmodules[i].hmodule == NULL) { - /* Not attempted before, so try to find this DLL */ + /* Try to find this DLL */ rtmodules[i].hmodule = GetModuleHandle(rtmodules[i].modulename); if (rtmodules[i].hmodule == NULL) { - /* - * Set to INVALID_HANDLE_VALUE so we know we have tried - * this one before, and won't try again. - */ - rtmodules[i].hmodule = INVALID_HANDLE_VALUE; continue; } else @@ -89,7 +84,6 @@ pgwin32_putenv(const char *envval) rtmodules[i].putenvFunc = (PUTENVPROC) GetProcAddress(rtmodules[i].hmodule, "_putenv"); if (rtmodules[i].putenvFunc == NULL) { - rtmodules[i].hmodule = INVALID_HANDLE_VALUE; continue; } } -- 2.8.1.windows.1