Skip to content

Commit 0852c7d

Browse files
authored
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.
1 parent b73dd02 commit 0852c7d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Modules/posixmodule.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,9 @@ dir_fd_converter(PyObject *o, void *p)
819819
}
820820
}
821821

822-
#ifdef HAVE_PUTENV
822+
/* Windows: _wputenv(env) copies the *env* string and doesn't require the
823+
caller to manage the variable memory. */
824+
#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
823825
# define PY_PUTENV_DICT
824826
#endif
825827

@@ -10130,8 +10132,10 @@ os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
1013010132
posix_error();
1013110133
goto error;
1013210134
}
10135+
/* _wputenv(env) copies the *env* string and doesn't require the caller
10136+
to manage the variable memory. */
10137+
Py_DECREF(unicode);
1013310138

10134-
posix_putenv_dict_setitem(name, unicode);
1013510139
Py_RETURN_NONE;
1013610140

1013710141
error:

0 commit comments

Comments
 (0)