bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126)
Windows: _wputenv(env) copies the *env* string and doesn't require
the caller to manage the variable memory.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e0eecfa..71b99fd 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -819,7 +819,9 @@
}
}
-#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 @@
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: