lordgamez commented on code in PR #2269:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2269#discussion_r4167066675
##########
core-framework/common/src/utils/Environment.cpp:
##########
@@ -107,7 +107,13 @@ bool Environment::unsetEnvironmentVariable(const char*
name) {
Environment::accessEnvironment([&success, name](){
#ifdef WIN32
- success = SetEnvironmentVariableA(name, nullptr);
+ const bool crt_success = _putenv_s(name, "") == 0;
+ bool windows_success = SetEnvironmentVariableA(name, nullptr) != 0;
+ if (!windows_success && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+ windows_success = true;
+ }
+
+ success = crt_success && windows_success;
Review Comment:
Currently on Windows our `setEnvironmentVariable` util uses both
`SetEnvironmentVariableA` which sets the process's environment variables and
`_putenv_s` that sets the C runtime's environment variables.
`unsetEnvironmentVariable` only used `SetEnvironmentVariableA` variable to
unset an envvar which left the CRT level variable in place and when a library
like AWS used `getenv` for getting a variable it found it even though we wanted
to unset it, this change keeps the 2 variable tables in sync and makes the
`setEnvironmentVariable` and `unsetEnvironmentVariable` utility functions
mirror each other.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]