// read_dot_valgrindrc() allocates the return value with
// VG_(malloc)(). We do not free f1_clo and f2_clo as they get
// put into VG_(args_for_valgrind) and so must persist.
- HChar* f1_clo = read_dot_valgrindrc( VG_(getenv)("HOME") );
+ HChar* home = VG_(getenv)("HOME");
+ HChar* f1_clo = home ? read_dot_valgrindrc( home ) : NULL;
HChar* env_clo = VG_(strdup)( VG_(getenv)(VALGRIND_OPTS) );
- HChar* f2_clo = read_dot_valgrindrc(".");
+ HChar* f2_clo = NULL;
+
+ // Don't read ./.valgrindrc if "." is the same as "$HOME", else its
+ // contents will be applied twice. (bug #142488)
+ if (home) {
+ HChar cwd[VKI_PATH_MAX+1];
+ Bool cwd_ok = VG_(getcwd)(cwd, VKI_PATH_MAX);
+ f2_clo = ( (cwd_ok && VG_STREQ(home, cwd))
+ ? NULL : read_dot_valgrindrc(".") );
+ }
if (f1_clo) add_args_from_string( f1_clo );
if (env_clo) add_args_from_string( env_clo );