From b4e5605e0aeef11e98d238d99ebcb381c9d26d5e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 12 May 2008 20:48:03 +0000 Subject: [PATCH] * unsetenv() was moving too much memory, thus corrupting the data after its allocation. * Added TODO to use a benaphore. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25478 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/stdlib/env.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/system/libroot/posix/stdlib/env.c b/src/system/libroot/posix/stdlib/env.c index 86cc5fea21..a9eefd621a 100644 --- a/src/system/libroot/posix/stdlib/env.c +++ b/src/system/libroot/posix/stdlib/env.c @@ -23,6 +23,7 @@ return err; +// TODO: Use benaphore! static sem_id sEnvLock; static bool sCopied; @@ -212,9 +213,11 @@ unsetenv(const char *name) env = find_variable(name, length, &index); if (env != NULL) { - // we don't free the memory for the slot, we just move the array contents + // 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() + 1)); + memmove(environ + index, environ + index + 1, + sizeof(char *) * (count_variables() - index)); } release_sem(sEnvLock);