Skip to main content

malloc_and_copy_bytes

Function malloc_and_copy_bytes 

Source
pub unsafe fn malloc_and_copy_bytes(data: &[u8], out_len: *mut usize) -> *mut u8
Expand description

Helper to allocate memory via malloc, copy Rust slice data into it, set the out_len pointer, and return the raw pointer. Returns null pointer on allocation failure.

ยงSafety

  • out_len must be a valid pointer to usize.
  • The caller must ensure the returned pointer (if not null) is eventually freed using ffi_free_bytes.
  • Operations involve raw pointers and calling libc::malloc, requiring unsafe block.