From 20e654cab0e77881198dfcde1cef0714ecc591f0 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Sat, 9 Oct 2010 09:09:01 +0000 Subject: [PATCH] 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 --- src/system/libroot/posix/stdlib/env.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/stdlib/env.cpp b/src/system/libroot/posix/stdlib/env.cpp index d71e42a5af..a6c577dd6b 100644 --- a/src/system/libroot/posix/stdlib/env.cpp +++ b/src/system/libroot/posix/stdlib/env.cpp @@ -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();