From b809a0b1c323529c2d7460962a3c688ad8aec3f4 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Tue, 6 Sep 2016 15:51:55 +0900
Subject: [PATCH 1/3] Cleanups in pgwin32_putenv().

- Added UCRT and all debug CRTs
- Condensed the array to one line per item (it was getting long)
- Test HMODULEs for NULL instead of zero
- Removed unnecessary CloseHandle() call
---
 src/port/win32env.c | 61 +++++++++++++++++++++++++----------------------------
 1 file changed, 29 insertions(+), 32 deletions(-)

diff --git a/src/port/win32env.c b/src/port/win32env.c
index e64065c..77f8334 100644
--- a/src/port/win32env.c
+++ b/src/port/win32env.c
@@ -45,36 +45,34 @@ pgwin32_putenv(const char *envval)
 		PUTENVPROC	putenvFunc;
 	}			rtmodules[] =
 	{
-		{
-			"msvcrt", 0, NULL
-		},						/* Visual Studio 6.0 / mingw */
-		{
-			"msvcr70", 0, NULL
-		},						/* Visual Studio 2002 */
-		{
-			"msvcr71", 0, NULL
-		},						/* Visual Studio 2003 */
-		{
-			"msvcr80", 0, NULL
-		},						/* Visual Studio 2005 */
-		{
-			"msvcr90", 0, NULL
-		},						/* Visual Studio 2008 */
-		{
-			"msvcr100", 0, NULL
-		},						/* Visual Studio 2010 */
-		{
-			"msvcr110", 0, NULL
-		},						/* Visual Studio 2012 */
-		{
-			"msvcr120", 0, NULL
-		},						/* Visual Studio 2013 */
-		{
-			"ucrtbase", 0, NULL
-		},						/* Visual Studio 2015 and later */
-		{
-			NULL, 0, NULL
-		}
+		/* Visual Studio 6.0 / mingw */
+		{"msvcrt",		NULL,	NULL},
+		{"msvcrtd",		NULL,	NULL},
+		/* Visual Studio 2002 */
+		{"msvcr70",		NULL,	NULL},
+		{"msvcr70d",	NULL,	NULL},
+		/* Visual Studio 2003 */
+		{"msvcr71",		NULL,	NULL},
+		{"msvcr71d",	NULL,	NULL},
+		/* Visual Studio 2005 */
+		{"msvcr80",		NULL,	NULL},
+		{"msvcr80d",	NULL,	NULL},
+		/* Visual Studio 2008 */
+		{"msvcr90",		NULL,	NULL},
+		{"msvcr90d",	NULL,	NULL},
+		/* Visual Studio 2010 */
+		{"msvcr100",	NULL,	NULL},
+		{"msvcr100d",	NULL,	NULL},
+		/* Visual Studio 2012 */
+		{"msvcr110",	NULL,	NULL},
+		{"msvcr110d",	NULL,	NULL},
+		/* Visual Studio 2013 */
+		{"msvcr120",	NULL,	NULL},
+		{"msvcr120d",	NULL,	NULL},
+		/* Visual Studio 2015 and later */
+		{"ucrtbase",	NULL,	NULL},
+		{"ucrtbased",	NULL,	NULL},
+		{NULL,			NULL,	NULL}
 	};
 	int			i;
 
@@ -82,7 +80,7 @@ pgwin32_putenv(const char *envval)
 	{
 		if (rtmodules[i].putenvFunc == NULL)
 		{
-			if (rtmodules[i].hmodule == 0)
+			if (rtmodules[i].hmodule == NULL)
 			{
 				/* Not attempted before, so try to find this DLL */
 				rtmodules[i].hmodule = GetModuleHandle(rtmodules[i].modulename);
@@ -100,7 +98,6 @@ pgwin32_putenv(const char *envval)
 					rtmodules[i].putenvFunc = (PUTENVPROC) GetProcAddress(rtmodules[i].hmodule, "_putenv");
 					if (rtmodules[i].putenvFunc == NULL)
 					{
-						CloseHandle(rtmodules[i].hmodule);
 						rtmodules[i].hmodule = INVALID_HANDLE_VALUE;
 						continue;
 					}
-- 
2.10.0

