From 8db78208f94db524c98af3f84caf6a8951e0d884 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 19 Nov 2020 15:50:54 +0100 Subject: [PATCH] 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 --- rust/src/conf.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rust/src/conf.rs b/rust/src/conf.rs index b85eb54a43..bc3582f73c 100644 --- a/rust/src/conf.rs +++ b/rust/src/conf.rs @@ -35,7 +35,8 @@ pub fn conf_get(key: &str) -> Option<&str> { let mut vptr: *const c_char = ptr::null_mut(); 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); return None; } @@ -88,8 +89,9 @@ impl ConfNode { let mut vptr: *const c_char = ptr::null_mut(); unsafe { + let s = CString::new(key).unwrap(); if ConfGetChildValue(self.conf, - CString::new(key).unwrap().as_ptr(), + s.as_ptr(), &mut vptr) != 1 { return None; } @@ -110,8 +112,9 @@ impl ConfNode { let mut vptr: c_int = 0; unsafe { + let s = CString::new(key).unwrap(); if ConfGetChildValueBool(self.conf, - CString::new(key).unwrap().as_ptr(), + s.as_ptr(), &mut vptr) != 1 { return false; }