Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39395: Clear env vars set by Python at exit #18078
Open
+28
−0
Conversation
Environment variables set by os.environ and os.putenv() are now cleared at exit. Python manages their memory which is released at exit.
This comment has been minimized.
This comment has been minimized.
|
cc @eduardo-elizondo @ericsnowcurrently @serhiy-storchaka @encukou (author and reviewers of PR #10854 and PR #15892). |
| static int | ||
| _posix_clear(PyObject *module) | ||
| { | ||
| Py_CLEAR(_posixstate(module)->billion); | ||
| #ifdef HAVE_UNSETENV | ||
| posix_unset_envvars(_posixstate(module)->posix_putenv_garbage); | ||
| #endif | ||
| Py_CLEAR(_posixstate(module)->posix_putenv_garbage); |
This comment has been minimized.
This comment has been minimized.
eduardo-elizondo
Jan 20, 2020
•
Contributor
Given that you are already doing these fixes around this, posix_putenv_garbage should also be guarded by HAVE_PUTENV (check its initialization in the init function).
This comment has been minimized.
This comment has been minimized.
|
Good catch, looks good to me |
This comment has been minimized.
This comment has been minimized.
|
Should the docs for os.environ and os.putenv be updated to note this explicit deletion? Is it possible that, on some platforms, existing programs might be using the current undefined behavior without crashing and thus might break with this change so it should be documented? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
vstinner commentedJan 20, 2020
•
edited by bedevere-bot
Environment variables set by os.environ and os.putenv() are now
cleared at exit. Python manages their memory which is released
at exit.
https://bugs.python.org/issue39395