mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 03:00:56 +00:00
ble works again after sleep - but we are still leaking
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "SimpleAllocator.h"
|
||||
#include "assert.h"
|
||||
|
||||
SimpleAllocator *activeAllocator;
|
||||
|
||||
SimpleAllocator::SimpleAllocator() { reset(); }
|
||||
|
||||
void *SimpleAllocator::alloc(size_t size)
|
||||
@@ -8,6 +10,7 @@ void *SimpleAllocator::alloc(size_t size)
|
||||
assert(nextFree + size <= sizeof(bytes));
|
||||
void *res = &bytes[nextFree];
|
||||
nextFree += size;
|
||||
Serial.printf("Total simple allocs %u\n", nextFree);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -18,3 +21,34 @@ void *operator new(size_t size, SimpleAllocator &p)
|
||||
{
|
||||
return p.alloc(size);
|
||||
}
|
||||
|
||||
AllocatorScope::AllocatorScope(SimpleAllocator &a)
|
||||
{
|
||||
assert(!activeAllocator);
|
||||
activeAllocator = &a;
|
||||
}
|
||||
|
||||
AllocatorScope::~AllocatorScope()
|
||||
{
|
||||
assert(activeAllocator);
|
||||
activeAllocator = NULL;
|
||||
}
|
||||
|
||||
/// Global new/delete, uses a simple allocator if it is in scope
|
||||
|
||||
void *operator new(size_t sz) throw(std::bad_alloc)
|
||||
{
|
||||
void *mem = activeAllocator ? activeAllocator->alloc(sz) : malloc(sz);
|
||||
if (mem)
|
||||
return mem;
|
||||
else
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
void operator delete(void *ptr) throw()
|
||||
{
|
||||
if (activeAllocator)
|
||||
Serial.println("Warning: leaking an active allocator object"); // We don't properly handle this yet
|
||||
else
|
||||
free(ptr);
|
||||
}
|
||||
Reference in New Issue
Block a user