mimalloc
mimalloc copied to clipboard
pointer being freed was not allocated
I'm trying out mimalloc, and immediately run into an issue, with the following test code. I've tried both with the latest master and with v2.1.7.
#include <algorithm>
#include <chrono>
#include <functional>
#include <iostream>
#include <thread>
#include <vector>
int main() {
std::vector<std::unique_ptr<std::size_t>> numbers(1024 * 1024 * 100);
std::vector<std::thread> threads(1);
std::atomic<std::size_t> index{};
auto start = std::chrono::system_clock::now();
for (auto& thread : threads) {
thread = std::thread{[&index, &numbers]() {
while (true) {
auto i = index.fetch_add(1, std::memory_order_relaxed);
if (i >= numbers.size()) return;
numbers[i] = std::make_unique<std::size_t>(i);
}
}};
}
for (auto& thread : threads) thread.join();
auto end = std::chrono::system_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Running on " << threads.size() << " threads took " << duration
<< std::endl;
}
Compiling this on macOS, like this:
c++ -std=c++20 -g -Wall -Wextra -L/Users/martijn/test -lmimalloc -o allocate allocate.cpp
leads to the following output when run:
allocate(16926,0x16d067000) malloc: *** error for object 0x3ff8c010020: pointer being freed was not allocated
allocate(16926,0x16d067000) malloc: *** set a breakpoint in malloc_error_break to debug