Description
Some allocators do not (wish to) permit reducing the size of a large allocation below a certain threshold. This leaves the GlobalAlloc::realloc implementation with two choices to handle such shrink operations:
- Create a new, smaller allocation, copy the contents from the large to the small allocation, free the large allocation
- Return a null pointer to indicate that the allocation has not changed
The second choice corresponds to the allocator behavior. Unfortunately std::alloc::Global.shrink translates this into an error instead of returning the old pointer:
rust/library/alloc/src/alloc.rs
Lines 289 to 290 in b2dd829
Downstream (e.g. RawVec) aborts the process if this happens even though there is still plenty of memory available.
Until GlobalAlloc has been completely replaced by AllocRef, I believe that it would be better if std::alloc::Global.shrink handled null pointer return values of the global allocator by returning the original allocation.