static int check_action = DEFAULT_CHECK_ACTION;
+/* ------------------ Testing support ----------------------------------*/
+
+static int perturb_byte;
+
+#define alloc_perturb(p, n) memset (p, (perturb_byte ^ 0xff) & 0xff, n)
+#define free_perturb(p, n) memset (p, perturb_byte & 0xff, n)
+
+
/* ------------------- Support for multiple arenas -------------------- */
#include "arena.c"
chunk2mem (victim));
*fb = victim->fd;
check_remalloced_chunk(av, victim, nb);
- return chunk2mem(victim);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
}
if (av != &main_arena)
victim->size |= NON_MAIN_ARENA;
check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
}
}
set_foot(remainder, remainder_size);
check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
/* remove from unsorted list */
if (av != &main_arena)
victim->size |= NON_MAIN_ARENA;
check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
/* place chunk in bin */
set_inuse_bit_at_offset(victim, size);
if (av != &main_arena)
victim->size |= NON_MAIN_ARENA;
- check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
}
/* Split */
else {
(av != &main_arena ? NON_MAIN_ARENA : 0));
set_head(remainder, remainder_size | PREV_INUSE);
set_foot(remainder, remainder_size);
- check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
}
+ check_malloced_chunk(av, victim, nb);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
}
set_inuse_bit_at_offset(victim, size);
if (av != &main_arena)
victim->size |= NON_MAIN_ARENA;
- check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
}
/* Split */
(av != &main_arena ? NON_MAIN_ARENA : 0));
set_head(remainder, remainder_size | PREV_INUSE);
set_foot(remainder, remainder_size);
- check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
}
+ check_malloced_chunk(av, victim, nb);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
}
set_head(remainder, remainder_size | PREV_INUSE);
check_malloced_chunk(av, victim, nb);
- return chunk2mem(victim);
+ void *p = chunk2mem(victim);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
}
/*
/*
Otherwise, relay to handle system-dependent cases
*/
- else
- return sYSMALLOc(nb, av);
+ else {
+ void *p = sYSMALLOc(nb, av);
+ if (__builtin_expect (perturb_byte, 0))
+ alloc_perturb (p, bytes);
+ return p;
+ }
}
}
errstr = "double free or corruption (fasttop)";
goto errout;
}
+
+ if (__builtin_expect (perturb_byte, 0))
+ free_perturb (mem, size - SIZE_SZ);
+
p->fd = *fb;
*fb = p;
}
goto errout;
}
+ if (__builtin_expect (perturb_byte, 0))
+ free_perturb (mem, size - SIZE_SZ);
+
/* consolidate backward */
if (!prev_inuse(p)) {
prevsize = p->prev_size;
case M_CHECK_ACTION:
check_action = value;
break;
+
+ case M_PERTURB:
+ perturb_byte = value;
+ break;
}
(void)mutex_unlock(&av->mutex);
return res;