]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126)
authorVictor Stinner <vstinner@python.org>
Wed, 22 Jan 2020 20:53:26 +0000 (21:53 +0100)
committerGitHub <noreply@github.com>
Wed, 22 Jan 2020 20:53:26 +0000 (21:53 +0100)
Windows: _wputenv(env) copies the *env* string and doesn't require
the caller to manage the variable memory.

Modules/posixmodule.c

index e0eecfa6d1143e23a0c9c31f8854c93f311bda7e..71b99fd836f1527662a12937814f04bbdd9d73b7 100644 (file)
@@ -819,7 +819,9 @@ dir_fd_converter(PyObject *o, void *p)
     }
 }
 
-#ifdef HAVE_PUTENV
+/* Windows: _wputenv(env) copies the *env* string and doesn't require the
+   caller to manage the variable memory. */
+#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
 #  define PY_PUTENV_DICT
 #endif
 
@@ -10130,8 +10132,10 @@ os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
         posix_error();
         goto error;
     }
+    /* _wputenv(env) copies the *env* string and doesn't require the caller
+       to manage the variable memory. */
+    Py_DECREF(unicode);
 
-    posix_putenv_dict_setitem(name, unicode);
     Py_RETURN_NONE;
 
 error: