From 2ad24b9ba191ed9d2b77dbf3f667504e05bc9707 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 18 May 2007 06:53:57 +0000 Subject: r22988: fixed 2 bugs in our unsetenv() replacement code 1) you must not free the memory, as it is possible the memory did not come from malloc (try it under valgrind to test) 2) the old code didn't cope with duplicate environment variables I hope this will fix some of the build farm errors on irix, and maybe solaris (This used to be commit ec6900171d066e927f004b621fb39cc7b8dcfd90) --- source4/lib/replace/replace.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source4/lib/replace') diff --git a/source4/lib/replace/replace.c b/source4/lib/replace/replace.c index db299130e5..87e73d001c 100644 --- a/source4/lib/replace/replace.c +++ b/source4/lib/replace/replace.c @@ -568,20 +568,24 @@ int rep_unsetenv(const char *name) { extern char **environ; size_t len = strlen(name); - size_t i; - int found = 0; + size_t i, count; - for (i=0; (environ && environ[i]); i++) { - if (found) { - environ[i-1] = environ[i]; - continue; - } + if (environ == NULL || getenv(name) == NULL) { + return 0; + } + for (i=0;environ[i];i++) /* noop */ ; + + count=i; + + for (i=0;i