unsetenv() should remove *any* occurence of name=value.

As with putenv() both value and name can be modified afterwise in our 
back, multiple occurence of the same name is a possibility.
Fix #6706. 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38904 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2010-10-09 09:09:01 +00:00
parent 5b2ed54046
commit 20e654cab0

View File

@ -279,12 +279,16 @@ unsetenv(const char *name)
copy_environ_to_heap_if_needed();
env = find_variable(name, length, &index);
if (env != NULL) {
while (env != NULL) {
// we don't free the memory for the slot, we just move the array
// contents
free(env);
memmove(environ + index, environ + index + 1,
sizeof(char *) * (count_variables() - index));
// search possible another occurence, introduced via putenv()
// and renamed since
env = find_variable(name, length, &index);
}
unlock_variables();