From: Alan Jenkins Date: Tue, 12 Sep 2017 12:17:54 +0000 (+0100) Subject: Fix valgrind usage in tests (#804) X-Git-Tag: v1.7.1~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8803948634d3f1435f9e96560f306960551952e3;p=thirdparty%2Frrdtool-1.x.git Fix valgrind usage in tests (#804) * Fix leak of socket address in rrd_daemon ==11140== 59 bytes in 1 blocks are definitely lost in loss record 132 ==11140== at 0x4C2DB9D: malloc (vg_replace_malloc.c:299) ==11140== by 0x6AD8CC9: strdup (in /usr/lib64/libc-2.24.so) ==11140== by 0x40A8AF: read_options (rrd_daemon.c:4493) ==11140== by 0x403114: main (rrd_daemon.c:4882) * create a file in case the caller has difficulty testing the rc e.g. because they pipe the output of rrdtool though something else. Additional valgrind suppressions were needed in 20 out of 21 tests. * tests: don't try to remove $VALGRIND_ERR_FILE when it doesn't exist Fix non-fatal warning. rm: cannot remove `/home/travis/build/oetiker/rrdtool-1.x/tests/ dump-restore-valgrind-err.tmp': No such file or directory --- diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 6092317b..937b86ae 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -3999,11 +3999,13 @@ static void open_listen_sockets_traditional(void) /* {{{ */ { if (config_listen_address_list_len > 0) { - for (size_t i = 0; i < config_listen_address_list_len; i++) + for (size_t i = 0; i < config_listen_address_list_len; i++) { open_listen_socket (config_listen_address_list[i]); + free_listen_socket (config_listen_address_list[i]); + } - rrd_free_ptrs((void ***) &config_listen_address_list, - &config_listen_address_list_len); + free(config_listen_address_list); + config_listen_address_list = NULL; } else { diff --git a/tests/functions b/tests/functions index 6b9f9069..e9456c2c 100644 --- a/tests/functions +++ b/tests/functions @@ -27,6 +27,11 @@ function blank { # https://stackoverflow.com/questions/4254610/valgrind-reports-memory-possibly-lost-when-using-glib-data-types) # we set some env. vars to work around them: +VALGRIND_ERR_FILE="${BASEDIR}/$(basename $0)-valgrind-err.tmp" +if [ -e "$VALGRIND_ERR_FILE" ]; then + rm "$VALGRIND_ERR_FILE" +fi + function valgrind { # use a sub shell, so setting environment variables only affects the current # rrdtool run and not subsequent ones @@ -70,7 +75,12 @@ function valgrind { exit $RC ) # - second: by returning the subshell exit code to the function caller - return $? + # Also create a file, in case the caller has difficulty testing the rc. + local RC=$? + if [ "$RC" == 111 ]; then + touch "$VALGRIND_ERR_FILE" + fi + return $RC } function verbose_rrdtool { @@ -79,7 +89,9 @@ function verbose_rrdtool { } function fail { - RC=$? + RC="$1" + shift + echo >&2 "FAILED: (rc=$RC)" "$@" if [ -n "$CONTINUE" ] ; then return @@ -87,10 +99,10 @@ function fail { if [ -n "$INTERACTIVE" ] ; then read -p "Continue? (y/n)" YN if [ "$YN" != 'y' ] ; then - exit $RC + exit 1 fi else - exit $RC + exit 1 fi } @@ -100,11 +112,18 @@ function ok { function report { RC=$? + if [ -e "$VALGRIND_ERR_FILE" ]; then + RC="valgrind error" + rm "$VALGRIND_ERR_FILE" + fi + if [ "$RC" = 0 ] ; then ok "$@" else - fail "$@" + fail "$RC" "$@" fi + + } function run_cached { @@ -160,12 +179,10 @@ if [ -z "$RRDTOOL" ] ; then STANDARD_RRDCACHED="$RRDCACHED" ;; valgrind) - echo >&2 "# Note: exit code 111 indicates a valgrind detected memory problem" RRDTOOL="valgrind $TOP_BUILDDIR/src/rrdtool" RRDCACHED="valgrind $TOP_BUILDDIR/src/rrdcached" ;; valgrind-logfile) - echo >&2 "# Note: exit code 111 indicates a valgrind detected memory problem" RRDTOOL="valgrind $TOP_BUILDDIR/src/rrdtool" RRDCACHED="valgrind $TOP_BUILDDIR/src/rrdcached" VALGRIND_LOGFILE="${BASEDIR}/$(basename $0)"-valgrind.log diff --git a/tests/valgrind-supressions b/tests/valgrind-supressions index dd0aee5a..bd90849b 100644 --- a/tests/valgrind-supressions +++ b/tests/valgrind-supressions @@ -19,3 +19,21 @@ fun:g_once_init_leave ... } +{ + g_type_register + Memcheck:Leak + fun:*alloc + ... + fun:g_type_register_* +} +{ + gobject_early_calloc + Memcheck:Leak + fun:calloc + fun:g_malloc0 + ... + obj:*/libgobject-* + ... + fun:_dl_init + ... +}