Skip to content

Commit 131b94a

Browse files
devzero2000gitster
authored andcommitted
test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34
In glibc >= 2.34 MALLOC_CHECK_ and MALLOC_PERTURB_ environment variables have been replaced by GLIBC_TUNABLES. Also the new glibc requires that you preload a library called libc_malloc_debug.so to get these features. Using the ordinary glibc system variable detect if this is glibc >= 2.34 and use GLIBC_TUNABLES and the new library. This patch was inspired by a Richard W.M. Jones ndbkit patch Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Elia Pinto <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c53a8c commit 131b94a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

t/test-lib.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,25 @@ else
518518
setup_malloc_check () {
519519
MALLOC_CHECK_=3 MALLOC_PERTURB_=165
520520
export MALLOC_CHECK_ MALLOC_PERTURB_
521+
if _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&
522+
_GLIBC_VERSION=${_GLIBC_VERSION#"glibc "} &&
523+
expr 2.34 \<= "$_GLIBC_VERSION" >/dev/null
524+
then
525+
g=
526+
LD_PRELOAD="libc_malloc_debug.so.0"
527+
for t in \
528+
glibc.malloc.check=1 \
529+
glibc.malloc.perturb=165
530+
do
531+
g="${g#:}:$t"
532+
done
533+
GLIBC_TUNABLES=$g
534+
export LD_PRELOAD GLIBC_TUNABLES
535+
fi
521536
}
522537
teardown_malloc_check () {
523538
unset MALLOC_CHECK_ MALLOC_PERTURB_
539+
unset LD_PRELOAD GLIBC_TUNABLES
524540
}
525541
fi
526542

0 commit comments

Comments
 (0)