From: Florian Krohm Date: Sat, 16 Jan 2016 21:44:31 +0000 (+0000) Subject: In ML_(am_allocate_segname) do not set the reference count of the X-Git-Tag: svn/VALGRIND_3_12_0~262 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45e3d3012dcbc1d93f645486fae4562f496e7943;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 0a8f6753d3..f6c1a41118 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 ef3d3ef564..8e74356621 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;