Summary: | calloc does not always zero memory | ||
---|---|---|---|
Product: | [Developer tools] valgrind | Reporter: | Eelco Dolstra <eelco> |
Component: | general | Assignee: | Julian Seward <jseward> |
Status: | RESOLVED FIXED | ||
Severity: | major | ||
Priority: | NOR | ||
Version: | 3.2 SVN | ||
Target Milestone: | --- | ||
Platform: | Unlisted Binaries | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: |
Description
Eelco Dolstra
2006-02-13 16:50:27 UTC
Wow. That's a good one. You discovered a bug in the brk() simulation introduced by the address space manager rewrite in 3.1.0. The following fixes it for me -- can you try it? Index: coregrind/m_syswrap/syswrap-generic.c =================================================================== --- coregrind/m_syswrap/syswrap-generic.c (revision 5646) +++ coregrind/m_syswrap/syswrap-generic.c (working copy) @@ -947,6 +947,21 @@ if (seg && seg->hasT) VG_(discard_translations)( newbrk, VG_(brk_limit) - newbrk, "do_brk(shrink)" ); + /* Since we're being lazy and not unmapping pages, we have to + zero out the area, so that if the area later comes back into + circulation, it will be filled with zeroes, as if it really + had been unmapped and later remapped. Be a bit paranoid and + try hard to ensure we're not going to segfault by doing the + write - check both ends of the range are in the same segment + and that segment is writable. */ + if (seg) { + /* pre: newbrk < VG_(brk_limit) + => newbrk <= VG_(brk_limit)-1 */ + NSegment* seg2 = VG_(am_find_nsegment)( VG_(brk_limit)-1 ); + if (seg2 && seg == seg2 && seg->hasW) + VG_(memset)( (void*)newbrk, 0, VG_(brk_limit) - newbrk ); + } + VG_(brk_limit) = newbrk; return newbrk; } It works! Thanks for your speedy fix :-) Fixed (valgrind r5647). |