Fix a crash in debug mode when working with huge strings.

Seems like a mimalloc bug.
Opened https://github.com/microsoft/mimalloc/issues/587 for this.
This commit is contained in:
Roman Gershman 2022-06-01 09:12:02 +03:00
parent eae5c08e76
commit 398b2b00bf
2 changed files with 14 additions and 1 deletions

View File

@ -14,6 +14,12 @@ void* MiMemoryResource::do_allocate(std::size_t size, std::size_t align) {
if (!res)
throw std::bad_alloc{};
// It seems that mimalloc has a bug with larger allocations that causes
// mi_heap_contains_block to lie. See https://github.com/microsoft/mimalloc/issues/587
// For now I avoid the check by checking the size. mi_usable_size works though.
DCHECK(size > 33554400 || mi_heap_contains_block(heap_, res));
size_t delta = mi_usable_size(res);
used_ += delta;
@ -23,7 +29,7 @@ void* MiMemoryResource::do_allocate(std::size_t size, std::size_t align) {
}
void MiMemoryResource::do_deallocate(void* ptr, std::size_t size, std::size_t align) {
DCHECK(mi_heap_contains_block(heap_, ptr));
DCHECK(size > 33554400 || mi_heap_contains_block(heap_, ptr));
size_t usable = mi_usable_size(ptr);

View File

@ -114,6 +114,13 @@ TEST_F(StringFamilyTest, Set) {
ASSERT_THAT(resp, "OK");
}
TEST_F(StringFamilyTest, SetHugeKey) {
const string key(36000000, 'b');
auto resp = Run({"set", key, "1"});
ASSERT_THAT(resp, "OK");
Run({"del", key});
}
TEST_F(StringFamilyTest, MGetSet) {
Run({"mset", "z", "0"}); // single key
auto resp = Run({"mget", "z"}); // single key