Skip to content

Actually free the returned string buffer #1

Open
@gwicke

Description

@gwicke

The current implementation doesn't properly free the returned buffer. Issues are:

  • Returning a CString as-is just works by accident (and lack of type checking across language barriers), as internally a CString is just a pointer. The correct solution would be to use into_ptr, which is in Rust unstable, but not in 1.2 yet. The CString can then be free by passing it back to Rust & doing from_ptr on it.
  • node-ffi doesn't expose finalizers, making it necessary to memcpy the return value, or manually free the returned buffer once done (error prone).
  • CStrings returned from Rust can't be simply freed, as Rust is using jemalloc & not libc malloc.

The best solution is probably to use a Rust vector instead, and then pass that back into Rust's vec::from_raw_parts in order to free it. Alternatively, a callback API (and async parsing) could work well too, especially if the JS callback copied the buffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions