1#include <assert.h>
2#include <stdlib.h>
3#include <string.h>
4
5// This tests that the suppression for the leak in setenv() works.  See bug
6// 188572.
7
8int main(void)
9{
10   char* val1 = "x";
11   char* val2 = "xx";
12   char* val3 = "xxx";
13
14   setenv("MYVAR", val1, /*overwrite*/0); // makes a copy which is later leaked
15   assert( 0 == strcmp(getenv("MYVAR"), val1) );
16
17   setenv("MYVAR", val2, /*overwrite*/1); // makes a copy which is later leaked
18   assert( 0 == strcmp(getenv("MYVAR"), val2) );
19
20   setenv("MYVAR", val3, /*overwrite*/0); // doesn't overwrite MYVAR=val2
21   assert( 0 == strcmp(getenv("MYVAR"), val2) );
22
23   putenv("MYVAR=xxxx");                  // no leak for putenv()
24   assert( 0 == strcmp(getenv("MYVAR"), "xxxx") );
25
26   unsetenv("MYVAR");
27   assert( NULL == getenv("MYVAR") );
28
29   return 0;
30}
31
32