-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Memory leak in Environment.SetEnvironmentVariable on Unix #4538
Comments
Looking at all of the PAL environment code and reading through the docs for the POSIX environment functions, the code we have in the PAL to deal with the environment seems dubious. It does some potentially dangerous things with the contents of
This plan obviously means that we will not support the case where a user wants to modify the environment from managed code and expects to see those changes reflected in a native library they PInvoke to, or vice versa. However, reading and writing environment variables in a shared library is problematic anyway (without some special consideration) because none of the POSIX environment functions are thread-safe. In addition, users who really want to keep the two versions of the environment in sync will have workarounds like PInvoking set/getenv (handling the threading concerns with their own locks) and then using Environment.Get/SetEnvironmentVariable, or the other way around. On the other hand, if we use the POSIX functions internally, user code can never safely PInvoke them since they won’t have a guarantee that one of the many CLR background threads isn’t using them for something. |
@adityamandaleeka It seems there is a problem with child processes. With your scheme, a child process launched by the managed process won't see the parent process environment changes, while it should inherit them. |
At least for processes launched via Process.Start, we already pass the current environment variables down: |
@janvorli I've opened a PR for this change, and I verified that |
@adityamandaleeka ok, thanks for verifying it! |
Fixed with dotnet/coreclr#3140. Closing the issue. |
Repro:
The problem appears to stem from here:
https://github.com/dotnet/coreclr/blob/2cf141dce5c3a22efd148e88f8a732835ee68336/src/pal/src/cruntime/misc.cpp#L687-L690
The text was updated successfully, but these errors were encountered: