Skip to content

using std.mem.Allocator.noResize in real allocators will leak memory #6460

Open
@npaskov

Description

@npaskov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions