Skip to content

Commit 02d9003

Browse files
peffgitster
authored andcommitted
test-lib: check malloc debug LD_PRELOAD before using
This fixes test failures across the suite on glibc platforms that don't have libc_malloc_debug.so.0. We added support for glibc's malloc checking routines long ago in a731fa9 (Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruption, 2012-09-14). Back then we didn't need to do any checks to see if the platform supported it. We were just setting some environment variables which would either enable it or not. That changed in 131b94a (test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34, 2022-03-04). Now that glibc split this out into libc_malloc_debug.so, we have to add it to LD_PRELOAD. We only do that when we detect glibc, but it's possible to have glibc but not the malloc debug library. In that case LD_PRELOAD will complain to stderr, and tests which check for an empty stderr will fail. You can work around this by setting TEST_NO_MALLOC_CHECK, which disables the feature entirely. But it's not obvious to know you need to do that. Instead, since this malloc checking is best-effort anyway, let's just automatically disable it when the LD_PRELOAD appears not to work. We can check it by running something simple that should work (and produce nothing on stderr) like "git version". Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 777489f commit 02d9003

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

t/test-lib.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,12 @@ then
593593
}
594594
else
595595
_USE_GLIBC_TUNABLES=
596+
_USE_GLIBC_PRELOAD=libc_malloc_debug.so.0
596597
if _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&
597598
_GLIBC_VERSION=${_GLIBC_VERSION#"glibc "} &&
598-
expr 2.34 \<= "$_GLIBC_VERSION" >/dev/null
599+
expr 2.34 \<= "$_GLIBC_VERSION" >/dev/null &&
600+
stderr=$(LD_PRELOAD=$_USE_GLIBC_PRELOAD git version 2>&1 >/dev/null) &&
601+
test -z "$stderr"
599602
then
600603
_USE_GLIBC_TUNABLES=YesPlease
601604
fi
@@ -607,7 +610,7 @@ else
607610
if test -n "$_USE_GLIBC_TUNABLES"
608611
then
609612
g=
610-
LD_PRELOAD="libc_malloc_debug.so.0"
613+
LD_PRELOAD=$_USE_GLIBC_PRELOAD
611614
for t in \
612615
glibc.malloc.check=1 \
613616
glibc.malloc.perturb=165

0 commit comments

Comments
 (0)