summaryrefslogtreecommitdiff
path: root/source3/lib/replace/replace.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-06-02 09:10:08 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:05 -0500
commite893d7f021d149803aa85e347e0a8acefde210ac (patch)
tree9af37dc1bf763b66cf94b8669ff1aa8ab6c77bb2 /source3/lib/replace/replace.c
parentb25bebb960eee796d5c5b1483f20250ed286894b (diff)
downloadsamba-e893d7f021d149803aa85e347e0a8acefde210ac.tar.gz
samba-e893d7f021d149803aa85e347e0a8acefde210ac.tar.bz2
samba-e893d7f021d149803aa85e347e0a8acefde210ac.zip
r23309: sync lib/replace with SAMBA_4_0
metze (This used to be commit 20965d800fcac0c55853fb12cdd36b5836fc7e56)
Diffstat (limited to 'source3/lib/replace/replace.c')
-rw-r--r--source3/lib/replace/replace.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/source3/lib/replace/replace.c b/source3/lib/replace/replace.c
index db299130e5..87e73d001c 100644
--- a/source3/lib/replace/replace.c
+++ b/source3/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<count;) {
if (strncmp(environ[i], name, len) == 0 && environ[i][len] == '=') {
- free(environ[i]);
- environ[i] = NULL;
- found = 1;
- continue;
+ /* note: we do _not_ free the old variable here. It is unsafe to
+ do so, as the pointer may not have come from malloc */
+ memmove(&environ[i], &environ[i+1], (count-i)*sizeof(char *));
+ count--;
+ } else {
+ i++;
}
}