]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix a bug in the debug code of find_chunk_for.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Wed, 18 Nov 2015 23:07:27 +0000 (23:07 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Wed, 18 Nov 2015 23:07:27 +0000 (23:07 +0000)
find_chunk_for has a special case for zero size block.
The special case was missing in the find_chunk_for_OLD.
So, when enabling the leak check debug, the following assert
is raised with ./vg-in-place ./memcheck/tests/leak-0
if you comment the lines (in find_chunk_for_OLD)
      if (a_lo == a_hi)
         a_hi++; // Special case for szB 0. See find_chunk_for.
and define VG_DEBUG_FIND_CHUNK

Memcheck: mc_leakcheck.c:327 (find_chunk_for): Assertion 'retVal == find_chunk_for_OLD ( ptr, chunks, n_chunks )' failed.

host stacktrace:
==7868==    at 0x38031535: show_sched_status_wrk (m_libcassert.c:343)
==7868==    by 0x38031641: report_and_quit (m_libcassert.c:415)
==7868==    by 0x38031723: vgPlain_assert_fail (m_libcassert.c:481)
==7868==    by 0x38004AA6: find_chunk_for (mc_leakcheck.c:327)
==7868==    by 0x38005236: lc_is_a_chunk_ptr (mc_leakcheck.c:538)
==7868==    by 0x3800556D: lc_push_without_clique_if_a_chunk_ptr (mc_leakcheck.c:893)
==7868==    by 0x38035234: apply_to_GPs_of_tid (m_machine.c:199)
==7868==    by 0x38035234: vgPlain_apply_to_GP_regs (m_machine.c:425)
==7868==    by 0x38006406: vgMemCheck_detect_memory_leaks (mc_leakcheck.c:1913)
==7868==    by 0x38015872: mc_handle_client_request (mc_main.c:6628)
==7868==    by 0x38047AB8: wrap_tool_handle_client_request (m_tooliface.c:280)
==7868==    by 0x3807C5C4: do_client_request (scheduler.c:2101)
==7868==    by 0x3807C5C4: vgPlain_scheduler (scheduler.c:1425)
==7868==    by 0x38089973: thread_wrapper (syswrap-linux.c:102)
==7868==    by 0x38089973: run_a_thread_NORETURN (syswrap-linux.c:155)

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

memcheck/mc_leakcheck.c

index d1d1f2398fd95af690b5951e063c7bd08677478e..6d1854edf7c64396cbe905bf2f8cab06b6bfaeb0 100644 (file)
 
 
 // Define to debug the memory-leak-detector.
+#define VG_DEBUG_FIND_CHUNK 0
 #define VG_DEBUG_LEAKCHECK 0
 #define VG_DEBUG_CLIQUE    0
  
@@ -255,7 +256,7 @@ static Int compare_MC_Chunks(const void* n1, const void* n2)
    return 0;
 }
 
-#if VG_DEBUG_LEAKCHECK
+#if VG_DEBUG_FIND_CHUNK
 // Used to sanity-check the fast binary-search mechanism.
 static 
 Int find_chunk_for_OLD ( Addr       ptr, 
@@ -270,6 +271,8 @@ Int find_chunk_for_OLD ( Addr       ptr,
       PROF_EVENT(MCPE_FIND_CHUNK_FOR_OLD_LOOP);
       a_lo = chunks[i]->data;
       a_hi = ((Addr)chunks[i]->data) + chunks[i]->szB;
+      if (a_lo == a_hi)
+         a_hi++; // Special case for szB 0. See find_chunk_for.
       if (a_lo <= ptr && ptr < a_hi)
          return i;
    }
@@ -320,7 +323,7 @@ Int find_chunk_for ( Addr       ptr,
       break;
    }
 
-#  if VG_DEBUG_LEAKCHECK
+#  if VG_DEBUG_FIND_CHUNK
    tl_assert(retVal == find_chunk_for_OLD ( ptr, chunks, n_chunks ));
 #  endif
    // VG_(printf)("%d\n", retVal);