From 9a60751a901f568bdeb154c4115235d4f3a0f8b9 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 20 Mar 2026 21:54:29 +0800 Subject: Apply clippy suggestions and improve code quality --- ffi/src/lib.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ffi/src') 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)); } } -- cgit