Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually free the returned string buffer #1

Open
gwicke opened this issue Aug 22, 2015 · 1 comment
Open

Actually free the returned string buffer #1

gwicke opened this issue Aug 22, 2015 · 1 comment

Comments

@gwicke
Copy link
Owner

gwicke commented Aug 22, 2015

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.

@gwicke
Copy link
Owner Author

gwicke commented Aug 22, 2015

/cc @cscott ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant