]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
A small fix to the "mempool trim" client request; the previous version
authorJulian Seward <jseward@acm.org>
Wed, 16 Aug 2006 17:51:28 +0000 (17:51 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 16 Aug 2006 17:51:28 +0000 (17:51 +0000)
didn't cope with zero-sized chunks properly.  (from Graydon Hoare).

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

memcheck/mc_malloc_wrappers.c

index 736bc01d1cdff182bc7e5e1f2a7f93e2da0fdbe7..02df6e207c75e3174b7159326726068a5e314cc0 100644 (file)
@@ -492,23 +492,25 @@ void MC_(mempool_trim)(Addr pool, Addr addr, SizeT size)
 
    tl_assert(chunks != NULL);
    for (i = 0; i < n_shadows; ++i) {
+
+      Addr lo, hi;
+
       mc = (MC_Chunk*) chunks[i];
 
-      if (mc->size == 0)
-         continue;
+      lo = mc->data;
+      hi = mc->size == 0 ? mc->data : mc->data + mc->size - 1;
 
 #define EXTENT_CONTAINS(x) ((addr <= (x)) && ((x) < addr + size))
 
-      if (EXTENT_CONTAINS(mc->data) &&
-          EXTENT_CONTAINS(mc->data + mc->size - 1)) {
+      if (EXTENT_CONTAINS(lo) && EXTENT_CONTAINS(hi)) {
 
          /* The current chunk is entirely within the trim extent: keep
             it. */
 
          continue;
 
-      } else if ( (! EXTENT_CONTAINS(mc->data)) &&
-                (! EXTENT_CONTAINS(mc->data + mc->size - 1)) ) {
+      } else if ( (! EXTENT_CONTAINS(lo)) &&
+                  (! EXTENT_CONTAINS(hi)) ) {
 
          /* The current chunk is entirely outside the trim extent:
             delete it. */
@@ -525,9 +527,8 @@ void MC_(mempool_trim)(Addr pool, Addr addr, SizeT size)
          /* The current chunk intersects the trim extent: remove,
             trim, and reinsert it. */
 
-         Addr lo, hi;
-         tl_assert(EXTENT_CONTAINS(mc->data) ||
-                   EXTENT_CONTAINS(mc->data + mc->size - 1));
+         tl_assert(EXTENT_CONTAINS(lo) ||
+                   EXTENT_CONTAINS(hi));
          if (VG_(HT_remove)(mp->chunks, (UWord)mc->data) == NULL) {
             MC_(record_free_error)(tid, (Addr)mc->data);
             VG_(free)(chunks);