From a34a222589a60312b58086ba7374e7c96884a2ba Mon Sep 17 00:00:00 2001 From: devzero2000 Date: Wed, 3 Jul 2013 14:08:58 +0000 Subject: Don't use MALLOC_CHECK_ and valgrind(memcheck) at the same time The test suite can use valgrind(memcheck) via 'configure --enable-valgrind' Memcheck wraps client calls to malloc(), and puts a "red zone" on each end of each block in order to detect access overruns. Memcheck already detects double free() (up to the limit of the buffer which remembers pending free()). Thus memcheck subsumes all the documented coverage of MALLOC_CHECK_. If MALLOC_CHECK_ is set non-zero when running memcheck, then the overruns that might be detected by MALLOC_CHECK_ would be overruns on the wrapped blocks which include the red zones. Thus MALLOC_CHECK_ would be checking memcheck, and not the client. This is not useful, and actually is wasteful. The only possible [documented] advantage of using MALLOC_CHECK_ and memcheck together, would be if MALLOC_CHECK_ detected duplicate free() in more cases than memcheck because memcheck's buffer is too small. --- CHANGES | 16 ++++++++++++++++ Makefile.am | 2 +- testit.sh | 44 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index 2c9941b..bb322af 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,20 @@ 1.17 -> 2.0: + - devzero2000: Don't use MALLOC_CHECK_ and valgrind(memcheck) at the + same time + The test suite can use valgrind(memcheck) via 'configure --enable-valgrind' + Memcheck wraps client calls to malloc(), and puts a "red zone" on + each end of each block in order to detect access overruns. + Memcheck already detects double free() (up to the limit of the buffer + which remembers pending free()). Thus memcheck subsumes all the + documented coverage of MALLOC_CHECK_. + If MALLOC_CHECK_ is set non-zero when running memcheck, then the + overruns that might be detected by MALLOC_CHECK_ would be overruns + on the wrapped blocks which include the red zones. Thus MALLOC_CHECK_ + would be checking memcheck, and not the client. This is not useful, + and actually is wasteful. The only possible [documented] advantage + of using MALLOC_CHECK_ and memcheck together, would be if MALLOC_CHECK_ + detected duplicate free() in more cases than memcheck because memcheck's + buffer is too small. - devzero2000: malloc check voodo portability quirk Get rid of a non portable shell export VAR=VALUE costruct. "Posix requires export to honor assignments diff --git a/Makefile.am b/Makefile.am index 725e674..41a22be 100644 --- a/Makefile.am +++ b/Makefile.am @@ -110,7 +110,7 @@ tdict_LDADD = $(top_builddir)/$(usrlib_LTLIBRARIES) test3_LDADD = $(top_builddir)/$(usrlib_LTLIBRARIES) TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) MUDFLAP_OPTIONS="$(MUDFLAP_OPTIONS)" testpoptrc="$(top_srcdir)/test-poptrc" PATH=.:../src:$$PATH \ - $(VALGRIND_ENVIRONMENT) \ + valgrind_environment="$(VALGRIND_ENVIRONMENT)" \ $(SHELL) diff --git a/testit.sh b/testit.sh index c2af1a5..dc14e7a 100755 --- a/testit.sh +++ b/testit.sh @@ -3,17 +3,43 @@ # malloc voo-doo ############################################### # see http://lists.gnupg.org/pipermail/gcrypt-devel/2010-June/001605.html -MALLOC_CHECK_=3 -export MALLOC_CHECK_ -# http://udrepper.livejournal.com/11429.html -MALLOC_PERTURB_=`expr \( $RANDOM % 255 \) + 1 ` -export MALLOC_PERTURB_ +# and http://udrepper.livejournal.com/11429.html +# and http://git.661346.n2.nabble.com/PATCHv2-Add-MALLOC-CHECK-and-MALLOC-PERTURB-libc-env-to-the-test-suite-for-detecting-heap-corruption-td7566915.html # -if [ -z "${MALLOC_PERTURB_}" ] # XXX: some shell don't have RANDOM ? +# Please note: we dont't use malloc_check if executing valgrind +# +# The test suite can use also valgrind(memcheck) via 'configure --enable-valgrind' +# +# Memcheck wraps client calls to malloc(), and puts a "red zone" on +# each end of each block in order to detect access overruns. +# Memcheck already detects double free() (up to the limit of the buffer +# which remembers pending free()). Thus memcheck subsumes all the +# documented coverage of MALLOC_CHECK_. +# If MALLOC_CHECK_ is set non-zero when running memcheck, then the +# overruns that might be detected by MALLOC_CHECK_ would be overruns +# on the wrapped blocks which include the red zones. Thus MALLOC_CHECK_ +# would be checking memcheck, and not the client. This is not useful, +# and actually is wasteful. The only possible [documented] advantage +# of using MALLOC_CHECK_ and memcheck together, would be if MALLOC_CHECK_ +# detected duplicate free() in more cases than memcheck because memcheck's +# buffer is too small. +# Therefore we don't use MALLOC_CHECK_ and valgrind(memcheck) at the +# same time. +############################################### +if [ -z "${valgrind_environment}" ] then - r=`ps -ef | cksum | cut -f1 -d" " 2>/dev/null` - [ -z "${r}" ] && r=1234567890 - export MALLOC_PERTURB_=`expr \( $r % 255 \) + 1 ` + MALLOC_CHECK_=3 + export MALLOC_CHECK_ + MALLOC_PERTURB_=`expr \( $RANDOM % 255 \) + 1 ` + export MALLOC_PERTURB_ + # + if [ -z "${MALLOC_PERTURB_}" ] # XXX: some shell don't have RANDOM ? + then + r=`ps -ef | cksum | cut -f1 -d" " 2>/dev/null` + [ -z "${r}" ] && r=1234567890 + MALLOC_PERTURB_=`expr \( $r % 255 \) + 1 ` + export MALLOC_PERTURB_ + fi fi run() { -- cgit v1.2.1