test-lib: set ASAN_OPTIONS variable before we run git

We turn off ASan's leak detection by default in the test suite because it's too noisy. But we don't do so until part-way through test-lib. This is before we've run any tests, but after we do our initial "./git" to see if the binary has even been built. When built with clang, this seems to work fine. However, using "gcc -fsanitize=address", the leak checker seems to complain more aggressively: $ ./git ... ==5352==ERROR: LeakSanitizer: detected memory leaks Direct leak of 2 byte(s) in 1 object(s) allocated from: #0 0x7f120e7afcf8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1cf8) #1 0x559fc2a3ce41 in do_xmalloc /home/peff/compile/git/wrapper.c:60 #2 0x559fc2a3cf1a in do_xmallocz /home/peff/compile/git/wrapper.c:100 #3 0x559fc2a3d0ad in xmallocz /home/peff/compile/git/wrapper.c:108 #4 0x559fc2a3d0ad in xmemdupz /home/peff/compile/git/wrapper.c:124 #5 0x559fc2a3d0ad in xstrndup /home/peff/compile/git/wrapper.c:130 #6 0x559fc274535a in main /home/peff/compile/git/common-main.c:39 #7 0x7f120dabd2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0) This is a leak in the sense that we never free it, but it's in a global that is meant to last the whole program. So it's not really interesting or in need of fixing. And at any rate, mentioning leaks outside of the test_expect blocks is certainly unwelcome, as it pollutes stderr. Let's bump the setting of ASAN_OPTIONS higher in test-lib.sh to catch our initial "can we even run git?" test. While we're at it, we can add a comment to make it a bit less inscrutable. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 10, 2017 at 09:24 UTC d0cc5796f35941d5a6ccd05146911f102bed57c4
1 file changed +8 -3
t/test-lib.sh
+8 -3
@@ -36,6 +36,14 @@ then
36 fi
37 GIT_BUILD_DIR="$TEST_DIRECTORY"/..
38
39 +# If we were built with ASAN, it may complain about leaks
40 +# of program-lifetime variables. Disable it by default to lower
41 +# the noise level. This needs to happen at the start of the script,
42 +# before we even do our "did we build git yet" check (since we don't
43 +# want that one to complain to stderr).
44 +: ${ASAN_OPTIONS=detect_leaks=0}
45 +export ASAN_OPTIONS
46 +
47 ################################################################
48 # It appears that people try to run tests without building...
49 "$GIT_BUILD_DIR/git" >/dev/null
@@ -148,9 +156,6 @@ else
156 }
157 fi
158
151 -: ${ASAN_OPTIONS=detect_leaks=0}
152 -export ASAN_OPTIONS
153 -
159 # Protect ourselves from common misconfiguration to export
160 # CDPATH into the environment
161 unset CDPATH