Fix crash with custom memory allocator