svn commit: samba r22988 - in branches/SAMBA_4_0/source/lib/replace: .

tridge at samba.org tridge at samba.org
Fri May 18 06:53:57 GMT 2007


Author: tridge
Date: 2007-05-18 06:53:57 +0000 (Fri, 18 May 2007)
New Revision: 22988

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=22988

Log:

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

Modified:
   branches/SAMBA_4_0/source/lib/replace/replace.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/replace/replace.c
===================================================================
--- branches/SAMBA_4_0/source/lib/replace/replace.c	2007-05-18 05:47:33 UTC (rev 22987)
+++ branches/SAMBA_4_0/source/lib/replace/replace.c	2007-05-18 06:53:57 UTC (rev 22988)
@@ -568,20 +568,24 @@
 {
 	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++;
 		}
 	}
 



More information about the samba-cvs mailing list