From ca58f30a5e728cda2802c7fafdc0770a45a5f8cb Mon Sep 17 00:00:00 2001 From: Eyal Soha Date: Tue, 2 Mar 2021 14:42:38 -0700 Subject: [PATCH] Bug 474160 - If errors-for-leak-kinds is specified, exit-on-first-error should only exit on one of the listed errors. It's possible for the user to specify in the memcheck that some errors should not cause an exit with the error-exitcode value. For those errors which would not cause an error exitcode, do not count them for the purposes of exiting after the first error. --- NEWS | 2 + coregrind/m_errormgr.c | 16 ++--- memcheck/tests/Makefile.am | 1 + .../leak-cases-exit-on-definite.stderr.exp | 64 +++++++++++++++++++ .../tests/leak-cases-exit-on-definite.vgtest | 3 + 5 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 memcheck/tests/leak-cases-exit-on-definite.stderr.exp create mode 100644 memcheck/tests/leak-cases-exit-on-definite.vgtest diff --git a/NEWS b/NEWS index d7686b80a9..7922646f31 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,8 @@ are not entered into bugzilla tend to get forgotten about or ignored. 466884 Missing writev uninit padding suppression for _XSend 471036 disInstr_AMD64: disInstr miscalculated next %rip on RORX imm8, m32/64, r32/6 471222 support tracking of file descriptors being double closed +474160 If errors-for-leak-kinds is specified, exit-on-first-error should only exit + on one of the listed errors. 475498 Add reallocarray wrapper 476320 Build failure with GCC 476331 clean up generated/distributed filter scripts diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 8f2fc0a965..40e36d162d 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -518,7 +518,7 @@ Bool VG_(is_action_requested) ( const HChar* action, Bool* clo ) * possibly, generate a suppression. */ static -void do_actions_on_error(const Error* err, Bool allow_db_attach) +void do_actions_on_error(const Error* err, Bool allow_db_attach, Bool count_error) { Bool still_noisy = True; @@ -543,7 +543,7 @@ void do_actions_on_error(const Error* err, Bool allow_db_attach) if (VG_(clo_gen_suppressions) == 1 && !still_noisy) VG_(clo_gen_suppressions) = 0; - if (VG_(clo_exit_on_first_error)) { + if (count_error && VG_(clo_exit_on_first_error)) { if (VG_(clo_xml)) VG_(printf_xml)("\n"); VG_(umsg)("\n"); @@ -581,7 +581,7 @@ void do_actions_on_error(const Error* err, Bool allow_db_attach) * calls do_actions_on_error. This optionally does a gdbserver call and optionally prints a suppression; both of these may require user input. */ -static void pp_Error ( const Error* err, Bool allow_db_attach, Bool xml ) +static void pp_Error ( const Error* err, Bool allow_db_attach, Bool xml, Bool count_error ) { /* If this fails, you probably specified your tool's method dictionary incorrectly. */ @@ -642,7 +642,7 @@ static void pp_Error ( const Error* err, Bool allow_db_attach, Bool xml ) } - do_actions_on_error(err, allow_db_attach); + do_actions_on_error(err, allow_db_attach, count_error); } @@ -849,7 +849,7 @@ void VG_(maybe_record_error) ( ThreadId tid, n_errs_found++; n_errs_shown++; /* Actually show the error; more complex than you might think. */ - pp_Error( p, /*allow_db_attach*/True, VG_(clo_xml) ); + pp_Error( p, /*allow_db_attach*/True, VG_(clo_xml), /* count_error */ True ); } else { n_supp_contexts++; n_errs_suppressed++; @@ -899,7 +899,7 @@ Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, const HChar* s, /* update stats */ n_errs_shown++; /* Actually show the error; more complex than you might think. */ - pp_Error(&err, allow_db_attach, VG_(clo_xml)); + pp_Error(&err, allow_db_attach, VG_(clo_xml), count_error); } return False; @@ -1025,7 +1025,7 @@ void VG_(show_all_errors) ( Int verbosity, Bool xml ) VG_(umsg)("\n"); VG_(umsg)("%d errors in context %d of %u:\n", p_min->count, i+1, n_err_contexts); - pp_Error( p_min, False/*allow_db_attach*/, False /* xml */ ); + pp_Error( p_min, False/*allow_db_attach*/, False /* xml */, True /* count_error */ ); // We're not printing XML -- we'd have exited above if so. vg_assert(! xml); @@ -1068,7 +1068,7 @@ void VG_(show_last_error) ( void ) return; } - pp_Error( errors, False/*allow_db_attach*/, False/*xml*/ ); + pp_Error( errors, False/*allow_db_attach*/, False/*xml*/, True/*count_error*/ ); } diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 76970529f2..20abbcfe1b 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -224,6 +224,7 @@ EXTRA_DIST = \ inltemplate.stderr.exp inltemplate.stdout.exp inltemplate.vgtest \ inltemplate.stderr.exp-old-gcc \ leak-0.vgtest leak-0.stderr.exp \ + leak-cases-exit-on-definite.vgtest leak-cases-exit-on-definite.stderr.exp \ leak-cases-full.vgtest leak-cases-full.stderr.exp \ leak-cases-possible.vgtest leak-cases-possible.stderr.exp \ leak-cases-summary.vgtest leak-cases-summary.stderr.exp \ diff --git a/memcheck/tests/leak-cases-exit-on-definite.stderr.exp b/memcheck/tests/leak-cases-exit-on-definite.stderr.exp new file mode 100644 index 0000000000..0534787035 --- /dev/null +++ b/memcheck/tests/leak-cases-exit-on-definite.stderr.exp @@ -0,0 +1,64 @@ + +All heap blocks were freed -- no leaks are possible + +LEAK SUMMARY: + definitely lost: 48 bytes in 3 blocks + indirectly lost: 32 bytes in 2 blocks + possibly lost: 96 bytes in 6 blocks + still reachable: 64 bytes in 4 blocks + suppressed: 0 bytes in 0 blocks +Rerun with --leak-check=full to see details of leaked memory + +leaked: 80 bytes in 5 blocks +dubious: 96 bytes in 6 blocks +reachable: 64 bytes in 4 blocks +suppressed: 0 bytes in 0 blocks + +HEAP SUMMARY: + in use at exit: 240 bytes in 15 blocks + total heap usage: 15 allocs, 0 frees, 240 bytes allocated + +16 bytes in 1 blocks are possibly lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:78) + by 0x........: main (leak-cases.c:107) + +16 bytes in 1 blocks are possibly lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:81) + by 0x........: main (leak-cases.c:107) + +16 bytes in 1 blocks are possibly lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:84) + by 0x........: main (leak-cases.c:107) + +16 bytes in 1 blocks are possibly lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:84) + by 0x........: main (leak-cases.c:107) + +16 bytes in 1 blocks are possibly lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:87) + by 0x........: main (leak-cases.c:107) + +16 bytes in 1 blocks are possibly lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:87) + by 0x........: main (leak-cases.c:107) + +16 bytes in 1 blocks are definitely lost in loss record ... of ... + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: mk (leak-cases.c:52) + by 0x........: f (leak-cases.c:74) + by 0x........: main (leak-cases.c:107) + + +Exit program on first error (--exit-on-first-error=yes) diff --git a/memcheck/tests/leak-cases-exit-on-definite.vgtest b/memcheck/tests/leak-cases-exit-on-definite.vgtest new file mode 100644 index 0000000000..a9deaccc1c --- /dev/null +++ b/memcheck/tests/leak-cases-exit-on-definite.vgtest @@ -0,0 +1,3 @@ +prog: leak-cases +vgopts: --error-exitcode=127 --errors-for-leak-kinds=definite --leak-check=full -s --exit-on-first-error=yes +stderr_filter_args: leak-cases.c -- 2.43.5