AP_HAL_Linux: added old_size to heap_realloc

This commit is contained in:
Andrew Tridgell 2022-12-23 09:50:37 +11:00
parent 13cbccc016
commit deb86be1da
2 changed files with 6 additions and 4 deletions

View File

@ -253,7 +253,7 @@ void *Util::allocate_heap_memory(size_t size)
return (void *)new_heap;
}
void *Util::heap_realloc(void *h, void *ptr, size_t new_size)
void *Util::heap_realloc(void *h, void *ptr, size_t old_size, size_t new_size)
{
if (h == nullptr) {
return nullptr;
@ -261,8 +261,10 @@ void *Util::heap_realloc(void *h, void *ptr, size_t new_size)
struct heap *heapp = (struct heap*)h;
// extract appropriate headers
size_t old_size = 0;
// extract appropriate headers. We use the old_size from the
// header not from the caller. We use SITL to catch cases they
// don't match (which would be a lua bug)
old_size = 0;
heap_allocation_header *old_header = nullptr;
if (ptr != nullptr) {
old_header = ((heap_allocation_header *)ptr) - 1;

View File

@ -75,7 +75,7 @@ public:
#ifdef ENABLE_HEAP
// heap functions, note that a heap once alloc'd cannot be dealloc'd
virtual void *allocate_heap_memory(size_t size) override;
virtual void *heap_realloc(void *h, void *ptr, size_t new_size) override;
virtual void *heap_realloc(void *h, void *ptr, size_t old_size, size_t new_size) override;
#endif // ENABLE_HEAP
/*