rust: fix warnings found by nightly compiler

warning: getting the inner pointer of a temporary `CString`
this `CString` is deallocated at the end of the statement,
bind it to a variable to extend its lifetime
pull/5596/head
Philippe Antoine 6 years ago committed by Victor Julien
parent 14aacbd067
commit 8db78208f9

@ -35,7 +35,8 @@ pub fn conf_get(key: &str) -> Option<&str> {
let mut vptr: *const c_char = ptr::null_mut(); let mut vptr: *const c_char = ptr::null_mut();
unsafe { unsafe {
if ConfGet(CString::new(key).unwrap().as_ptr(), &mut vptr) != 1 { let s = CString::new(key).unwrap();
if ConfGet(s.as_ptr(), &mut vptr) != 1 {
SCLogDebug!("Failed to find value for key {}", key); SCLogDebug!("Failed to find value for key {}", key);
return None; return None;
} }
@ -88,8 +89,9 @@ impl ConfNode {
let mut vptr: *const c_char = ptr::null_mut(); let mut vptr: *const c_char = ptr::null_mut();
unsafe { unsafe {
let s = CString::new(key).unwrap();
if ConfGetChildValue(self.conf, if ConfGetChildValue(self.conf,
CString::new(key).unwrap().as_ptr(), s.as_ptr(),
&mut vptr) != 1 { &mut vptr) != 1 {
return None; return None;
} }
@ -110,8 +112,9 @@ impl ConfNode {
let mut vptr: c_int = 0; let mut vptr: c_int = 0;
unsafe { unsafe {
let s = CString::new(key).unwrap();
if ConfGetChildValueBool(self.conf, if ConfGetChildValueBool(self.conf,
CString::new(key).unwrap().as_ptr(), s.as_ptr(),
&mut vptr) != 1 { &mut vptr) != 1 {
return false; return false;
} }

Loading…
Cancel
Save