mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
enable DebugAllocation in heap.cpp when NDEBUG is not defined
This commit is contained in:
parent
22852dcffa
commit
30c7107aa3
22
src/heap.cpp
22
src/heap.cpp
@ -33,7 +33,12 @@ const bool Verbose = false;
|
||||
const bool Verbose2 = false;
|
||||
const bool Debug = false;
|
||||
const bool DebugFixies = false;
|
||||
|
||||
#ifdef NDEBUG
|
||||
const bool DebugAllocation = false;
|
||||
#else
|
||||
const bool DebugAllocation = true;
|
||||
#endif
|
||||
|
||||
#define ACQUIRE(x) MutexLock MAKE_NAME(monitorLock_) (x)
|
||||
|
||||
@ -423,7 +428,9 @@ class Segment {
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
free(context, data, (footprint(capacity())) * BytesPerWord);
|
||||
if (data) {
|
||||
free(context, data, (footprint(capacity())) * BytesPerWord);
|
||||
}
|
||||
data = 0;
|
||||
map = 0;
|
||||
}
|
||||
@ -1675,8 +1682,7 @@ void* tryAllocate(Context* c, unsigned size)
|
||||
ACQUIRE(c->lock);
|
||||
|
||||
if (DebugAllocation) {
|
||||
size = pad(size);
|
||||
size += 2 * BytesPerWord;
|
||||
size = pad(size) + 2 * BytesPerWord;
|
||||
}
|
||||
|
||||
if (size + c->count < c->limit) {
|
||||
@ -1699,21 +1705,21 @@ void* tryAllocate(Context* c, unsigned size)
|
||||
void free(Context* c, const void* p, unsigned size) {
|
||||
ACQUIRE(c->lock);
|
||||
|
||||
expect(c->system, c->count >= size);
|
||||
|
||||
if (DebugAllocation) {
|
||||
memset(const_cast<void*>(p), 0xFE, size);
|
||||
size = pad(size) + 2 * BytesPerWord;
|
||||
|
||||
size = pad(size);
|
||||
memset(const_cast<void*>(p), 0xFE, size - (2 * BytesPerWord));
|
||||
|
||||
p = static_cast<const uintptr_t*>(p) - 1;
|
||||
|
||||
expect(c->system, static_cast<const uintptr_t*>(p)[0] == 0x22377322);
|
||||
|
||||
expect(c->system, static_cast<const uintptr_t*>(p)
|
||||
[1 + (size / BytesPerWord)] == 0x22377322);
|
||||
[(size / BytesPerWord) - 1] == 0x22377322);
|
||||
}
|
||||
|
||||
expect(c->system, c->count >= size);
|
||||
|
||||
c->system->free(p);
|
||||
c->count -= size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user