]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Suppress a leak in setenv(). Fixes bug 188572.
authorNicholas Nethercote <njn@valgrind.org>
Fri, 26 Jun 2009 07:00:00 +0000 (07:00 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 26 Jun 2009 07:00:00 +0000 (07:00 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10380

darwin9.supp
memcheck/tests/darwin/Makefile.am
memcheck/tests/darwin/env.c [new file with mode: 0644]
memcheck/tests/darwin/env.stderr.exp [new file with mode: 0644]
memcheck/tests/darwin/env.vgtest [new file with mode: 0644]

index c397019b2918c561b7ebe63c99ca963d730f576f..bbcfd66f613d6c2e8fc5c40f29219d64d0851191 100644 (file)
    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
+}
+
 
 ##----------------------------------------------------------------------##
 #
index 8cc9f29ef9b1b6f94d24bf16d762030882b76bc4..1027300ec01b7bb66ad6c8eab831d9213e4c0d72 100644 (file)
@@ -6,6 +6,7 @@ dist_noinst_SCRIPTS = filter_stderr
 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 @@ EXTRA_DIST = \
        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 (file)
index 0000000..9e36b15
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/darwin/env.vgtest b/memcheck/tests/darwin/env.vgtest
new file mode 100644 (file)
index 0000000..75d46ff
--- /dev/null
@@ -0,0 +1,2 @@
+prog: env
+vgopts: -q --leak-check=full