Made checks on client have own macro.
This commit is contained in:
@@ -469,7 +469,7 @@ namespace snmalloc
|
||||
return;
|
||||
}
|
||||
|
||||
# ifndef NDEBUG
|
||||
# ifdef CHECK_CLIENT
|
||||
if (size > 64 || address_cast(super) != address_cast(p))
|
||||
{
|
||||
error("Not deallocating start of an object");
|
||||
@@ -817,7 +817,7 @@ namespace snmalloc
|
||||
{
|
||||
Superslab* super = Superslab::get(p);
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifdef CHECK_CLIENT
|
||||
if (p->target_id() != super->get_allocator()->id())
|
||||
error("Detected memory corruption. Potential use-after-free");
|
||||
#endif
|
||||
@@ -1013,7 +1013,7 @@ namespace snmalloc
|
||||
|
||||
void small_dealloc(Superslab* super, void* p, uint8_t sizeclass)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
#ifdef CHECK_CLIENT
|
||||
Slab* slab = Slab::get(p);
|
||||
if (!slab->is_start_of_object(super, p))
|
||||
{
|
||||
@@ -1150,7 +1150,7 @@ namespace snmalloc
|
||||
stats().sizeclass_dealloc(sizeclass);
|
||||
bool was_full = slab->dealloc(p, large_allocator.memory_provider);
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifdef CHECK_CLIENT
|
||||
if (!is_multiple_of_sizeclass(
|
||||
sizeclass_to_size(sizeclass),
|
||||
address_cast(slab) + SUPERSLAB_SIZE - address_cast(p)))
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
// The CHECK_CLIENT macro is used to turn on minimal checking of the client
|
||||
// calling the API correctly.
|
||||
#if !defined(NDEBUG) && !defined(CHECK_CLIENT)
|
||||
# define CHECK_CLIENT
|
||||
#endif
|
||||
|
||||
// 0 intermediate bits results in power of 2 small allocs. 1 intermediate
|
||||
// bit gives additional sizeclasses at the midpoint between each power of 2.
|
||||
// 2 intermediate bits gives 3 intermediate sizeclasses, etc.
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace snmalloc
|
||||
/// simple corruptions.
|
||||
static void store_next(void* p, uint16_t head)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
#ifndef CHECK_CLIENT
|
||||
*static_cast<size_t*>(p) = head;
|
||||
#else
|
||||
*static_cast<size_t*>(p) =
|
||||
@@ -112,7 +112,7 @@ namespace snmalloc
|
||||
static uint16_t follow_next(void* node)
|
||||
{
|
||||
size_t next = *static_cast<size_t*>(node);
|
||||
#ifndef NDEBUG
|
||||
#ifdef CHECK_CLIENT
|
||||
if (((next ^ POISON) ^ (next << (bits::BITS - 16))) > 0xFFFF)
|
||||
error("Detected memory corruption. Use-after-free.");
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace snmalloc
|
||||
|
||||
bool was_full = meta.is_full();
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifdef CHECK_CLIENT
|
||||
if (meta.is_unused())
|
||||
error("Detected potential double free.");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user