Skip to content

Commit

Permalink
Merge pull request #8 from alsaibie/dashing
Browse files Browse the repository at this point in the history
added guard to prevent dealloc and realloc on null ptr
  • Loading branch information
ralph-lange authored Jun 30, 2020
2 parents e0e8579 + 3b1a79f commit 60b5950
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions microros_olimex_e407_extensions/Src/allocators.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ void * __freertos_allocate(size_t size, void * state){
void __freertos_deallocate(void * pointer, void * state){
(void) state;
// printf("-- Free %d (prev: %d B)\n",getBlockSize(pointer), xPortGetFreeHeapSize());
usedMemory -= getBlockSize(pointer);
vPortFree(pointer);
if (NULL != pointer){
usedMemory -= getBlockSize(pointer);
vPortFree(pointer);
}
}

void * __freertos_reallocate(void * pointer, size_t size, void * state){
(void) state;
// printf("-- Realloc %d -> %d (prev: %d B)\n",getBlockSize(pointer),size, xPortGetFreeHeapSize());
absoluteUsedMemory += size;
usedMemory += size;
usedMemory -= getBlockSize(pointer);
return pvPortRealloc(pointer,size);
if (NULL != pointer){
usedMemory -= getBlockSize(pointer);
return pvPortRealloc(pointer,size);
} else {
return pvPortMalloc(size);
}
}

void * __freertos_zero_allocate(size_t number_of_elements, size_t size_of_element, void * state){
Expand Down

0 comments on commit 60b5950

Please sign in to comment.