Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39395: Clear env vars set by Python at exit #18078

Open
wants to merge 1 commit into
base: master
from

Conversation

@vstinner
Copy link
Member

vstinner commented Jan 20, 2020

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

Environment variables set by os.environ and os.putenv() are now
cleared at exit. Python manages their memory which is released
at exit.
@vstinner

This comment has been minimized.

Copy link
Member Author

vstinner commented Jan 20, 2020

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.

Copy link
@eduardo-elizondo

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).

@eduardo-elizondo

This comment has been minimized.

Copy link
Contributor

eduardo-elizondo commented Jan 20, 2020

Good catch, looks good to me 👍

@ned-deily

This comment has been minimized.

Copy link
Member

ned-deily commented Jan 20, 2020

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?

@vstinner

This comment has been minimized.

Copy link
Member Author

vstinner commented Jan 21, 2020

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?

Yes, it is possible. Python 3.8 was safe: the memory was never released, so environment variables remained available and didn't crash.

I will first implement https://bugs.python.org/issue39406 before updating this PR to document the incompatible change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.