Replace calls to putenv with setenv (#18530)

* Replace calls to C `putenv` with C `setenv` to remove possible memory leaks

* Add test of correct behaviour on invalid input

* Fix style in tests/stdlib/tos.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update tests/stdlib/tos.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update tests/stdlib/tos.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Add comment with bug number to tests/stdlib/tos.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Fix possible msvc arch issues

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
This commit is contained in:
Caden Haustein 2021-07-23 08:04:29 +00:00 • committed by GitHub
commit f62f4159f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -614,6 +614,9 @@ block osenv:
doAssert existsEnv(dummyEnvVar) == false
delEnv(dummyEnvVar) # deleting an already deleted env var
doAssert existsEnv(dummyEnvVar) == false
block: # putEnv, bug #18502
doAssertRaises(OSError): putEnv("DUMMY_ENV_VAR_PUT=DUMMY_VALUE", "NEW_DUMMY_VALUE")
doAssertRaises(OSError): putEnv("", "NEW_DUMMY_VALUE")
block:
doAssert getEnv("DUMMY_ENV_VAR_NONEXISTENT", "") == ""
doAssert getEnv("DUMMY_ENV_VAR_NONEXISTENT", " ") == " "