From 19b05d8f17d0f0b416dcac107c24f5d312ed7a02 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 14 Jul 2022 14:57:39 +0900 Subject: [PATCH 1/2] capi: fix 'unused return value' warnings from `cargo check` --- regex-capi/src/rure.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/regex-capi/src/rure.rs b/regex-capi/src/rure.rs index dc49b20a3..ec79fe410 100644 --- a/regex-capi/src/rure.rs +++ b/regex-capi/src/rure.rs @@ -257,8 +257,8 @@ ffi_fn! { fn rure_iter_capture_names_free(it: *mut IterCaptureNames) { unsafe { let it = &mut *it; - while let Some(ptr) = it.name_ptrs.pop(){ - CString::from_raw(ptr); + while let Some(ptr) = it.name_ptrs.pop() { + drop(CString::from_raw(ptr)); } Box::from_raw(it); } @@ -624,6 +624,6 @@ fn rure_escape( ffi_fn! { fn rure_cstring_free(s: *mut c_char) { - unsafe { CString::from_raw(s); } + unsafe { drop(CString::from_raw(s)); } } } From 1324f2d59a7977b606143ab4511026256adb7a24 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 14 Jul 2022 22:20:47 +0900 Subject: [PATCH 2/2] capi: explicitly call `drop()` for calling `free()` via `Box` --- regex-capi/src/error.rs | 2 +- regex-capi/src/rure.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/regex-capi/src/error.rs b/regex-capi/src/error.rs index 2ca3fae80..a269a3913 100644 --- a/regex-capi/src/error.rs +++ b/regex-capi/src/error.rs @@ -54,7 +54,7 @@ ffi_fn! { ffi_fn! { fn rure_error_free(err: *mut Error) { - unsafe { Box::from_raw(err); } + unsafe { drop(Box::from_raw(err)); } } } diff --git a/regex-capi/src/rure.rs b/regex-capi/src/rure.rs index ec79fe410..d2e1539ed 100644 --- a/regex-capi/src/rure.rs +++ b/regex-capi/src/rure.rs @@ -151,7 +151,7 @@ ffi_fn! { ffi_fn! { fn rure_free(re: *const Regex) { - unsafe { Box::from_raw(re as *mut Regex); } + unsafe { drop(Box::from_raw(re as *mut Regex)); } } } @@ -260,7 +260,7 @@ ffi_fn! { while let Some(ptr) = it.name_ptrs.pop() { drop(CString::from_raw(ptr)); } - Box::from_raw(it); + drop(Box::from_raw(it)); } } } @@ -316,7 +316,7 @@ ffi_fn! { ffi_fn! { fn rure_iter_free(it: *mut Iter) { - unsafe { Box::from_raw(it); } + unsafe { drop(Box::from_raw(it)); } } } @@ -407,7 +407,7 @@ ffi_fn! { ffi_fn! { fn rure_captures_free(captures: *const Captures) { - unsafe { Box::from_raw(captures as *mut Captures); } + unsafe { drop(Box::from_raw(captures as *mut Captures)); } } } @@ -447,7 +447,7 @@ ffi_fn! { ffi_fn! { fn rure_options_free(options: *mut Options) { - unsafe { Box::from_raw(options); } + unsafe { drop(Box::from_raw(options)); } } } @@ -527,7 +527,7 @@ ffi_fn! { ffi_fn! { fn rure_set_free(re: *const RegexSet) { - unsafe { Box::from_raw(re as *mut RegexSet); } + unsafe { drop(Box::from_raw(re as *mut RegexSet)); } } }