The test for whether to use valgrind runs:
/bin/bash -c 'exit 0'
This looks pretty harmless; unfortunately, bash itself causes problems:
$ valgrind -q --error-exitcode=1 --leak-check=full /bin/bash -c 'exit 0'
==32197== Invalid free() / delete / delete / realloc()
==32197== at 0x4C2ED5B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32197== by 0x45E1D0: ??? (in /bin/bash)
==32197== by 0x45E37F: run_unwind_frame (in /bin/bash)
==32197== by 0x47B664: parse_and_execute (in /bin/bash)
==32197== by 0x4209D6: ??? (in /bin/bash)
==32197== by 0x41F893: main (in /bin/bash)
==32197== Address 0x423b828 is in the brk data segment 0x4228000-0x423bfff
Here I was using the provided Ubuntu 16.04 build of bash:
$ bash --version
GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
Maybe use some other known-available utility that doesn't play weird tricks with memory? /bin/ls works for me!