Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdlib/getenv.c
Show First 20 Lines • Show All 685 Lines • ▼ Show 20 Lines | while (__findenv(name, nameLen, &envNdx, true) != NULL) { | ||||
envNdx--; | envNdx--; | ||||
newEnvActive--; | newEnvActive--; | ||||
} | } | ||||
if (newEnvActive != envActive) | if (newEnvActive != envActive) | ||||
__rebuild_environ(newEnvActive); | __rebuild_environ(newEnvActive); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | |||||
* Unset all variable by flagging it as inactive. No variable is | |||||
scf: Suggestion: `Unset all variables by flagging them ...` | |||||
Done Inline Actionsagreed emaste: agreed | |||||
* ever freed. | |||||
*/ | |||||
int | |||||
clearenv(void) | |||||
{ | |||||
int ndx; | |||||
/* Initialize environment. */ | |||||
if (__merge_environ() == -1 || (envVars == NULL && __build_env() == -1)) | |||||
return (-1); | |||||
/* Remove from the end to not shuffle memory too much. */ | |||||
for (ndx = envVarsTotal - 1; ndx >= 0; ndx--) { | |||||
envVars[ndx].active = false; | |||||
markjUnsubmitted Not Done Inline ActionsDon't you need to adjust envActive here? markj: Don't you need to adjust `envActive` here? | |||||
oshogboAuthorUnsubmitted Done Inline ActionsAs far as I understand the __rebuild_environ is adjusting it. In unsetenv we also don't adjust envActive. oshogbo: As far as I understand the `__rebuild_environ` is adjusting it. In unsetenv we also don't… | |||||
if (envVars[ndx].putenv) | |||||
__remove_putenv(ndx); | |||||
} | |||||
__rebuild_environ(0); | |||||
Done Inline ActionsIt has been many years since I have looked at this code, so bear with me. :) There may be two other options, which you may have already looked at:
Those may work, but you would have to test to make sure. scf: It has been many years since I have looked at this code, so bear with me. :)
There may be two… | |||||
Done Inline ActionsThe final call of __rebuild_environ(0) at the end of the function will have environ set to intEnviron which is not NULL at that point. The Linux man page says environ will be set to NULL. I also recommend a unit test for that. scf: The final call of `__rebuild_environ(0)` at the end of the function will have `environ` set to… | |||||
Done Inline ActionsYea that looks much easier. I did like you suggested and added some more tests. oshogbo: Yea that looks much easier. I did like you suggested and added some more tests. | |||||
return (0); | |||||
} |
Suggestion: Unset all variables by flagging them ...