Skip to content

Commit

Permalink
fix: avoid double-freeing due to copy in io align unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lokitoth committed Feb 1, 2024
1 parent 59197c3 commit 5deef6b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion vowpalwabbit/core/tests/io_alignment_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ struct positioned_ptr
: allocation(allocation), allocation_unit(malloc(allocation)), p(reinterpret_cast<int8_t*>(allocation_unit))
{
}
~positioned_ptr() { free(allocation_unit); }
positioned_ptr(const positioned_ptr&) = delete;
positioned_ptr(positioned_ptr&& original) : allocation(original.allocation), allocation_unit(original.allocation_unit)
{
original.allocation_unit = nullptr;
}

~positioned_ptr()
{
if (allocation_unit != nullptr) { free(allocation_unit); }
}

void realign(align_t alignment, align_t offset)
{
Expand Down

0 comments on commit 5deef6b

Please sign in to comment.