Skip to content

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

Closed
@Erik-S

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.

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