Function ffi_support::destroy_c_string [−][src]
pub unsafe fn destroy_c_string(cstring: *mut c_char)
Free the memory of a string created by rust_string_to_c
on the rust heap. If c_string
is
null, this is a no-op.
See the define_string_destructor!
macro which may be used for exposing this function over
the FFI.
Safety
This is inherently unsafe, since we’re deallocating memory. Be sure
- Nobody can use the memory after it’s deallocated.
- The memory was actually allocated on this heap (and it’s not a string from the other side of
the FFI which was allocated on e.g. the C heap).
- If multiple separate rust libraries are in use (for example, as DLLs) in a single program, you must also make sure that the rust library that allocated the memory is also the one that frees it.
See documentation for define_string_destructor!
, which gives a more complete overview of the
potential issues.