Use 0xcc (not 0xcd) for clearing malloc() blocks too.
[pintos-anon] / src / threads / malloc.c
index 487e93875ef4124ac314a7355429d4c2a632d1ab..0cb5f9d997def46ce1570b40eb5d9e1195216f3c 100644 (file)
@@ -198,7 +198,7 @@ free (void *p)
     }
 
 #ifndef NDEBUG
-  memset (b, 0xcd, d->block_size);
+  memset (b, 0xcc, d->block_size);
 #endif
   
   lock_acquire (&d->lock);
@@ -228,8 +228,16 @@ static struct arena *
 block_to_arena (struct block *b)
 {
   struct arena *a = pg_round_down (b);
+
+  /* Check that the arena is valid. */
   ASSERT (a != NULL);
   ASSERT (a->magic == ARENA_MAGIC);
+
+  /* Check that the block is properly aligned for the arena. */
+  ASSERT (a->desc == NULL
+          || (pg_ofs (b) - sizeof *a) % a->desc->block_size == 0);
+  ASSERT (a->desc != NULL || pg_ofs (b) == sizeof *a);
+
   return a;
 }