Skip to content

Commit e26732d

Browse files
authored
Fix svs::lib::allocator (#106)
This PR fixes allocate/deallocate mismatch to resolve Valgrind memory checks errors.
1 parent f2380c1 commit e26732d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

include/svs/lib/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ template <typename T> struct Allocator {
6161
}
6262

6363
constexpr void deallocate(value_type* ptr, size_t count) noexcept {
64-
::operator delete(ptr, count);
64+
::operator delete(static_cast<void*>(ptr), sizeof(T) * count, std::align_val_t(alignof(T)));
6565
}
6666

6767
// Intercept zero-argument construction to do default initialization.

include/svs/lib/threads/threadlocal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ template <typename T, size_t Alignment = CACHE_LINE_BYTES> struct AlignedAllocat
8282
}
8383

8484
void deallocate(value_type* ptr, size_t count) noexcept {
85-
::operator delete(ptr, count, std::align_val_t{alignment});
85+
size_t bytes = alignment * lib::div_round_up(sizeof(T) * count, alignment);
86+
::operator delete(static_cast<void*>(ptr), bytes, std::align_val_t{alignment});
8687
}
8788
};
8889

0 commit comments

Comments
 (0)