]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
In ML_(am_allocate_segname) do not set the reference count of the
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 16 Jan 2016 21:44:31 +0000 (21:44 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 16 Jan 2016 21:44:31 +0000 (21:44 +0000)
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

coregrind/m_aspacemgr/aspacemgr-linux.c
coregrind/m_aspacemgr/aspacemgr-segnames.c

index 0a8f6753d3b2d28ceacedfe69963d3199edafcee..f6c1a411180b12ddd58b3425cd8c4c80c4d06681 100644 (file)
@@ -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
index ef3d3ef564be3c584138afa5c537329fee927cfb..8e743566212d9270af1920ef0cc2dbe451e0f71a 100644 (file)
@@ -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;