using std.mem.Allocator.noResize in real allocators will leak memory #6460
Labels
standard library
This issue involves writing Zig code for the standard library.
Milestone
According to current Allocator convention, calling resizeFn with new_len of 0 must release the memory block.
The noResize function has no knowledge of how to release memory, so if used as suggested, as resizeFn in allocators with no in-place resize ability, it will simply report success and leak the memory.
I would suggest providing explicit Allocator.freeFn for releasing memory, which will provide cleaner set of responsibilities for the Allocator functions and will allow to just have resizeFn==null if allocator does not support in-place resize.
Alternatively, if keeping current Allocator semantics, the noResize function should be removed or hidden, and allocators should always provide resizeFn capable of releasing their own allocated memory.
The text was updated successfully, but these errors were encountered: