From 06b4c67fa5b599e9490ccb89dd52944762e81727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 1 Aug 2008 15:08:06 +0000 Subject: [PATCH] * Instead of just deleting the array, we have to delete its contents, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26720 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/stdlib/env.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/system/libroot/posix/stdlib/env.c b/src/system/libroot/posix/stdlib/env.c index d486ef2808..052058567f 100644 --- a/src/system/libroot/posix/stdlib/env.c +++ b/src/system/libroot/posix/stdlib/env.c @@ -46,6 +46,23 @@ unlock_variables(void) } +static void +free_variables(void) +{ + int32 i; + + if (sManagedEnviron == NULL) + return; + + for (i = 0; sManagedEnviron[i] != NULL; i++) { + free(sManagedEnviron[i]); + } + + free(sManagedEnviron); + sManagedEnviron = NULL; +} + + static int32 count_variables(void) { @@ -108,7 +125,7 @@ copy_environ_to_heap_if_needed(void) if (sManagedEnviron != NULL) { // free previously used "environ"; it has been changed by an application - free(sManagedEnviron); + free_variables(); } sManagedEnviron = malloc((count_variables() + 1) * sizeof(char *)); @@ -201,8 +218,8 @@ clearenv(void) { lock_variables(); - free(sManagedEnviron); - sManagedEnviron = environ = NULL; + free_variables(); + environ = NULL; unlock_variables(); }