Skip to content

Commit

Permalink
Fix FragmentationBenchmark (facebookincubator#10878)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookincubator#10878

Fixes a bug where a null allocator object is passed to the 'Block' class whereas
it expects a reference to a valid object. This can then result in a segfault when
it tried to access the null object.

Reviewed By: xiaoxmeng

Differential Revision: D61926803
  • Loading branch information
Bikramjeet Vig authored and facebook-github-bot committed Aug 28, 2024
1 parent d16b195 commit a522104
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions velox/common/memory/tests/FragmentationBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ using namespace facebook::velox;
using namespace facebook::velox::memory;

struct Block {
explicit Block(MemoryAllocator& _allocator) : allocator(_allocator) {}
explicit Block(MemoryAllocator* _allocator) : allocator(_allocator) {}

~Block() {
if (data != nullptr) {
free(data);
}
if (allocation != nullptr) {
allocator.freeNonContiguous(*allocation);
if (allocator != nullptr) {
if (allocation != nullptr) {
allocator->freeNonContiguous(*allocation);
}
allocator->freeContiguous(contiguous);
}
allocator.freeContiguous(contiguous);
}

MemoryAllocator& allocator;
MemoryAllocator* allocator;
size_t size = 0;
char* data = nullptr;
std::shared_ptr<Allocation> allocation;
Expand Down Expand Up @@ -91,7 +93,7 @@ class FragmentationTest {
}

void allocate(size_t size) {
auto block = std::make_unique<Block>(*memory_);
auto block = std::make_unique<Block>(memory_.get());
block->size = size;
if (memory_) {
if (size <= 8 << 20) {
Expand Down

0 comments on commit a522104

Please sign in to comment.