AllocatorLog: support nulls in deallocate() and reallocate()

This commit is contained in:
Benoit Blanchon
2023-07-17 14:46:00 +02:00
parent c4e5051a7a
commit 65c67d317a
2 changed files with 8 additions and 5 deletions

View File

@ -31,8 +31,10 @@ class ArmoredAllocator : public Allocator {
// this way we make sure we support relocation
void* new_ptr = malloc(new_size);
memset(new_ptr, '#', new_size); // erase
memcpy(new_ptr, ptr, std::min(new_size, new_size));
free(ptr);
if (ptr) {
memcpy(new_ptr, ptr, std::min(new_size, new_size));
free(ptr);
}
return new_ptr;
}
};