replacing the global operator newdelete and allocating memory within these leads to heap corruption

From std::allocator::allocate allocator allocates n “things” not n bytes. You should change:

T* allocate(std::size_t n) const { return (T*)malloc(n); }


T* allocate(std::size_t n) const { return (T*)malloc(sizeof(T) * n); }

Why do i corrupt the heap in the constructor of allocations_map?

Because the constructor of elements stored in that map access allocated memory out-of-bounds.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top