]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix a bug reported by Bruce Lowekamp involving the interaction of
authorNicholas Nethercote <njn@valgrind.org>
Fri, 12 Jan 2007 23:59:50 +0000 (23:59 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 12 Jan 2007 23:59:50 +0000 (23:59 +0000)
--gen-suppressions with leak checking.  Added a regtest for it.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6514

coregrind/m_errormgr.c
memcheck/tests/Makefile.am
memcheck/tests/nanoleak2.c [new file with mode: 0644]
memcheck/tests/nanoleak2.stderr.exp [new file with mode: 0644]
memcheck/tests/nanoleak2.vgtest [new file with mode: 0644]

index e9fef133e726508d0583a2d27ebfe283d344242a..3204c69ff8a6b54706f68eda5009e290df2eb4fa 100644 (file)
@@ -474,6 +474,8 @@ void do_actions_on_error(Error* err, Bool allow_db_attach)
    just for pretty printing purposes. */
 static Bool is_first_shown_context = True;
 
+static Int  n_errs_shown = 0;
+
 /* Top-level entry point to the error management subsystem.
    All detected errors are notified here; this routine decides if/when the
    user should see the error. */
@@ -487,7 +489,6 @@ void VG_(maybe_record_error) ( ThreadId tid,
           VgRes  exe_res          = Vg_MedRes;
    static Bool   stopping_message = False;
    static Bool   slowdown_message = False;
-   static Int    n_errs_shown     = 0;
 
    /* After M_COLLECT_NO_ERRORS_AFTER_SHOWN different errors have
       been found, or M_COLLECT_NO_ERRORS_AFTER_FOUND total errors
@@ -649,7 +650,8 @@ Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s,
                          void* extra, ExeContext* where, Bool print_error,
                          Bool allow_db_attach, Bool count_error )
 {
-   Error  err;
+   Error err;
+   Supp *su;
 
    /* Build ourselves the error */
    construct_error ( &err, tid, ekind, a, s, extra, where );
@@ -663,7 +665,8 @@ Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s,
       not copying 'extra'. */
    (void)VG_TDICT_CALL(tool_update_extra, &err);
 
-   if (NULL == is_suppressible_error(&err)) {
+   su = is_suppressible_error(&err);
+   if (NULL == su) {
       if (count_error)
          n_errs_found++;
 
@@ -672,13 +675,14 @@ Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s,
             VG_(message)(Vg_UserMsg, "");
          pp_Error(&err);
          is_first_shown_context = False;
+         n_errs_shown++;
+         do_actions_on_error(&err, allow_db_attach);
       }
-      do_actions_on_error(&err, allow_db_attach);
-
       return False;
 
    } else {
       n_errs_suppressed++;
+      su->count++;
       return True;
    }
 }
index d7189d24e1930d7e4ab5e06293333743f1cf7154..73537d88dc089e9a3017291d4204a8de172179a7 100644 (file)
@@ -81,6 +81,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \
        mmaptest.stderr.exp mmaptest.vgtest \
        nanoleak.stderr.exp nanoleak.vgtest \
        nanoleak_supp.stderr.exp nanoleak_supp.vgtest nanoleak.supp \
+       nanoleak2.stderr.exp nanoleak2.vgtest \
        new_nothrow.stderr.exp new_nothrow.vgtest \
        new_override.stderr.exp new_override.stdout.exp new_override.vgtest \
        null_socket.stderr.exp null_socket.vgtest \
@@ -155,7 +156,7 @@ check_PROGRAMS = \
        malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
        match-overrun \
        memalign_test memalign2 memcmptest mempool mmaptest \
-       nanoleak new_nothrow \
+       nanoleak nanoleak2 new_nothrow \
        null_socket oset_test overlap \
        partiallydefinedeq \
        partial_load pdb-realloc pdb-realloc2 \
diff --git a/memcheck/tests/nanoleak2.c b/memcheck/tests/nanoleak2.c
new file mode 100644 (file)
index 0000000..d4758df
--- /dev/null
@@ -0,0 +1,19 @@
+
+// Bruce Lowekamp <lowekamp@sipeerior.com> reported that in a program with a
+// reachable leak, if you do:
+//
+//   valgrind --leak-check=yes --gen-suppressions=yes --show-reachable=no -q
+//
+// it gives the y/n/c suppression prompt for errors that aren't shown.  This
+// test checks that is fixed.
+
+#include <stdlib.h>
+
+int* a;
+
+int main ( void )
+{
+  a = malloc(1000);  // Becomes a reachable leak.
+  a[0] = 0;
+  return a[0];
+}
diff --git a/memcheck/tests/nanoleak2.stderr.exp b/memcheck/tests/nanoleak2.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/nanoleak2.vgtest b/memcheck/tests/nanoleak2.vgtest
new file mode 100644 (file)
index 0000000..de0e70c
--- /dev/null
@@ -0,0 +1,2 @@
+vgopts: --leak-check=yes --gen-suppressions=yes --show-reachable=no -q
+prog: nanoleak2