]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix valgrind usage in tests (#804)
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Tue, 12 Sep 2017 12:17:54 +0000 (13:17 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 12 Sep 2017 12:17:54 +0000 (14:17 +0200)
* 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

src/rrd_daemon.c
tests/functions
tests/valgrind-supressions

index 6092317bc35e3b0cf21155346a848ac895852292..937b86ae8f01091a7adfeb1af6f6858820c10b3a 100644 (file)
@@ -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
   {
index 6b9f9069918c0baa6a001d82adb34000cc786e29..e9456c2c4a624b9f3a62974ccd22217875100e05 100644 (file)
@@ -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
index dd0aee5a43968cdcc7cfec7fd470b344a235b21a..bd90849b1aa28d979fd16e011a119205d7ace02c 100644 (file)
    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
+    ...
+}