Skip to content

Let user specify function to use for freeing foreign buffers #8465

Closed

Description

@Erik-S

Pull #8296 adds a type (CString) to wrap char pointers returned from C code into Rust strings. The Drop impl on CString function always calls libc::free(). This is not generally correct on Windows.

On Windows, each function or API specifies which free()-like function to use. Not using the correct function will cause problems.

Raymond Chen (at the Old New Thing blog) has more details on why Windows works this way: http://blogs.msdn.com/b/oldnewthing/archive/2006/09/15/755966.aspx

I don't know Rust well enough to say what the correct fix is. Maybe pass in a function pointer to the constructor that is called at drop? The pointer could replace the "owns_buffer" bool if we use an optional pointer.

Activity

  1. emberian commented on Jan 6, 2014

    @emberian
    Contributor

    Presumably allocator parameterization would solve this. But it's such a hairball to deal with.

  2. alexcrichton commented on Jan 19, 2015

    @alexcrichton
    Member

    This was resolved in #20507

  3. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions