Don't call SetEnvironmentVariable() when removing an environment variable,
authorMagnus Hagander <magnus@hagander.net>
Thu, 12 Feb 2009 12:53:34 +0000 (12:53 +0000)
committerMagnus Hagander <magnus@hagander.net>
Thu, 12 Feb 2009 12:53:34 +0000 (12:53 +0000)
as this seems to crash on at least some versions of MingW. Our current usage
of this function does not require it, so it should be ok to ignore.

src/port/win32env.c

index 9e8565aa70bce055129e504e93c19007a61f5776..26ddf3bfed987e07d26874742596ea5d6a8d7d16 100644 (file)
@@ -64,12 +64,18 @@ pgwin32_putenv(const char *envval)
                return -1;
        *cp = '\0';
        cp++;
-       if (strlen(cp) == 0)
-               cp = NULL;
-       if (!SetEnvironmentVariable(envcpy, cp))
+       if (strlen(cp))
        {
-               free(envcpy);
-               return -1;
+               /*
+                * Only call SetEnvironmentVariable() when we are adding a variable,
+                * not when removing it. Calling it on both crashes on at least certain
+                * versions of MingW.
+                */
+               if (!SetEnvironmentVariable(envcpy, cp))
+               {
+                       free(envcpy);
+                       return -1;
+               }
        }
        free(envcpy);