commit b28a423827a1c7917c6f3f3eba23b9432077dfbd Author: florian Date: Sat Jan 16 21:44:31 2016 +0000 In ML_(am_allocate_segname) do not set the reference count of the slot to 1. Rather do that in add_segment which is where the segment refering to that name actually comes into existence. Properly handle the case in add_segment where the to-be-added segment and one (or more) of the segments it replaces have the same name This may occur when doing a mremap. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15761 a5019735-40e9-0310-863c-91ae7b9d1cf9 diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 0a8f675..f6c1a41 100644 --- a/coregrind/m_aspacemgr/aspacemgr-linux.c +++ b/coregrind/m_aspacemgr/aspacemgr-linux.c @@ -1445,6 +1445,15 @@ static void add_segment ( const NSegment* seg ) split_nsegments_lo_and_hi( sStart, sEnd, &iLo, &iHi ); + /* Increase the reference count of SEG's name. We need to do this + *before* decreasing the reference count of the names of the replaced + segments. Consider the case where the segment name of SEG and one of + the replaced segments are the same. If the refcount of that name is 1, + then decrementing first would put the slot for that name on the free + list. Attempting to increment the refcount later would then fail + because the slot is no longer allocated. */ + ML_(am_inc_refcount)(seg->fnIdx); + /* Now iLo .. iHi inclusive is the range of segment indices which seg will replace. If we're replacing more than one segment, slide those above the range down to fill the hole. Before doing diff --git a/coregrind/m_aspacemgr/aspacemgr-segnames.c b/coregrind/m_aspacemgr/aspacemgr-segnames.c index ef3d3ef..8e74356 100644 --- a/coregrind/m_aspacemgr/aspacemgr-segnames.c +++ b/coregrind/m_aspacemgr/aspacemgr-segnames.c @@ -309,7 +309,7 @@ ML_(am_allocate_segname)(const HChar *name) freeslot_chain = next_freeslot; else put_slotindex(prev, next_freeslot); - put_refcount(ix, 1); + put_refcount(ix, 0); put_slotsize(ix, size); VG_(strcpy)(segnames + ix, name); ++num_segnames; @@ -336,7 +336,7 @@ ML_(am_allocate_segname)(const HChar *name) /* copy it in */ ix = segnames_used; - put_refcount(ix, 1); + put_refcount(ix, 0); put_slotsize(ix, len + 1); VG_(strcpy)(segnames + ix, name); segnames_used += need; commit e345eb50c0c5e96ac60b2bc21fbe9f281c20b9e6 Author: florian Date: Sat Jan 16 21:12:57 2016 +0000 Remove code that has no effect. Looks like a leftover from early debugging days. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15760 a5019735-40e9-0310-863c-91ae7b9d1cf9 diff --git a/coregrind/m_aspacemgr/aspacemgr-segnames.c b/coregrind/m_aspacemgr/aspacemgr-segnames.c index 761608d..ef3d3ef 100644 --- a/coregrind/m_aspacemgr/aspacemgr-segnames.c +++ b/coregrind/m_aspacemgr/aspacemgr-segnames.c @@ -250,9 +250,7 @@ dec_refcount(UInt ix) UInt size = get_slotsize(ix); /* Chain this slot in the freelist */ put_slotindex(ix, freeslot_chain); - get_slotindex(ix); put_slotsize(ix + slotsize_size, size); - get_slotindex(ix); freeslot_chain = ix; --num_segnames; if (0) VG_(am_show_nsegments)(0, "AFTER DECREASE rc -> 0");