Suppress a leak in setenv().  Fixes bug 188572.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10380 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/darwin9.supp b/darwin9.supp
index c397019..bbcfd66 100644
--- a/darwin9.supp
+++ b/darwin9.supp
@@ -143,6 +143,18 @@
    fun:puts
 }
 
+# Genuine leaks.
+# See https://bugs.kde.org/show_bug.cgi?id=188572 about this;  it's
+# unavoidable due to BSD setenv() semantics.
+{
+   <insert a suppression name here>
+   Memcheck:Leak
+   fun:malloc_zone_malloc
+   fun:__setenv
+   fun:setenv$UNIX2003
+   fun:main
+}
+
 
 ##----------------------------------------------------------------------##
 #
diff --git a/memcheck/tests/darwin/Makefile.am b/memcheck/tests/darwin/Makefile.am
index 8cc9f29..1027300 100644
--- a/memcheck/tests/darwin/Makefile.am
+++ b/memcheck/tests/darwin/Makefile.am
@@ -6,6 +6,7 @@
 noinst_HEADERS = scalar.h
 
 EXTRA_DIST = \
+	env.stderr.exp env.vgtest \
 	pth-supp.stderr.exp pth-supp.vgtest \
 	scalar.stderr.exp scalar.vgtest \
 	scalar_fork.stderr.exp scalar_fork.vgtest \
@@ -13,6 +14,7 @@
 	scalar_vfork.stderr.exp scalar_vfork.vgtest
 
 check_PROGRAMS = \
+	env \
 	pth-supp \
 	scalar \
 	scalar_fork \
diff --git a/memcheck/tests/darwin/env.c b/memcheck/tests/darwin/env.c
new file mode 100644
index 0000000..9e36b15
--- /dev/null
+++ b/memcheck/tests/darwin/env.c
@@ -0,0 +1,31 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+// This tests that the suppression for the leak in setenv() works.  See bug
+// 188572.
+
+int main(void)
+{
+   char* val1 = "x";
+   char* val2 = "xx";
+   char* val3 = "xxx";
+
+   setenv("MYVAR", val1, /*overwrite*/0); // makes a copy which is later leaked
+   assert( 0 == strcmp(getenv("MYVAR"), val1) );
+
+   setenv("MYVAR", val2, /*overwrite*/1); // makes a copy which is later leaked
+   assert( 0 == strcmp(getenv("MYVAR"), val2) );
+
+   setenv("MYVAR", val3, /*overwrite*/0); // doesn't overwrite MYVAR=val2
+   assert( 0 == strcmp(getenv("MYVAR"), val2) );
+
+   putenv("MYVAR=xxxx");                  // no leak for putenv()
+   assert( 0 == strcmp(getenv("MYVAR"), "xxxx") );
+
+   unsetenv("MYVAR");
+   assert( NULL == getenv("MYVAR") );
+
+   return 0;
+}
+
diff --git a/memcheck/tests/darwin/env.stderr.exp b/memcheck/tests/darwin/env.stderr.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/memcheck/tests/darwin/env.stderr.exp
diff --git a/memcheck/tests/darwin/env.vgtest b/memcheck/tests/darwin/env.vgtest
new file mode 100644
index 0000000..75d46ff
--- /dev/null
+++ b/memcheck/tests/darwin/env.vgtest
@@ -0,0 +1,2 @@
+prog: env
+vgopts: -q --leak-check=full