diff options
Diffstat (limited to 'ffi/src/lib.rs')
| -rw-r--r-- | ffi/src/lib.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 7ffcb00..4682136 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -3,11 +3,18 @@ pub use constants::*; #[unsafe(no_mangle)] #[allow(nonstandard_style)] -pub extern "C" fn JV_FreeString(ptr: *mut libc::c_char) { - if ptr.is_null() { - return; - } +/// # Safety +/// +/// This function must be called with a pointer that was obtained from +/// `JV_Const_*` functions or `std::ffi::CString::into_raw()`. The pointer +/// must not be null unless it was explicitly returned as null from the +/// allocating function. After calling this function, the pointer becomes +/// invalid and must not be used again. +pub unsafe extern "C" fn JV_FreeString(ptr: *mut libc::c_char) { unsafe { + if ptr.is_null() { + return; + } drop(std::ffi::CString::from_raw(ptr)); } } |
