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:
@@ -279,12 +279,16 @@ unsetenv(const char *name)
|
|||||||
copy_environ_to_heap_if_needed();
|
copy_environ_to_heap_if_needed();
|
||||||
|
|
||||||
env = find_variable(name, length, &index);
|
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
|
// we don't free the memory for the slot, we just move the array
|
||||||
// contents
|
// contents
|
||||||
free(env);
|
free(env);
|
||||||
memmove(environ + index, environ + index + 1,
|
memmove(environ + index, environ + index + 1,
|
||||||
sizeof(char *) * (count_variables() - index));
|
sizeof(char *) * (count_variables() - index));
|
||||||
|
|
||||||
|
// search possible another occurence, introduced via putenv()
|
||||||
|
// and renamed since
|
||||||
|
env = find_variable(name, length, &index);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_variables();
|
unlock_variables();
|
||||||
|
|||||||
Reference in New Issue
Block a user