From 3587033d9eb633dd1599c7f9e0223e10e074efb3 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 7 Jun 2021 13:29:11 +0200 Subject: [PATCH] files: construct with default, free on drop Update protocols. --- rust/src/filecontainer.rs | 19 ++++++------------- rust/src/http2/http2.rs | 3 +-- rust/src/nfs/nfs.rs | 9 ++------- rust/src/smb/smb.rs | 3 +-- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/rust/src/filecontainer.rs b/rust/src/filecontainer.rs index 9e01502b73..d61d246164 100644 --- a/rust/src/filecontainer.rs +++ b/rust/src/filecontainer.rs @@ -37,19 +37,6 @@ pub struct Files { } impl Files { - pub fn new() -> Files { - Files { - files_ts:FileContainer::default(), - files_tc:FileContainer::default(), - flags_ts:0, - flags_tc:0, - } - } - pub fn free(&mut self) { - self.files_ts.free(); - self.files_tc.free(); - } - pub fn get(&mut self, direction: u8) -> (&mut FileContainer, u16) { if direction == STREAM_TOSERVER { @@ -68,6 +55,12 @@ pub struct FileContainer { tail: * mut c_void, } +impl Drop for FileContainer { + fn drop(&mut self) { + self.free(); + } +} + impl Default for FileContainer { fn default() -> Self { Self { head: ptr::null_mut(), diff --git a/rust/src/http2/http2.rs b/rust/src/http2/http2.rs index e3bd02cc4b..fe09c60a7e 100644 --- a/rust/src/http2/http2.rs +++ b/rust/src/http2/http2.rs @@ -371,13 +371,12 @@ impl HTTP2State { dynamic_headers_tc: HTTP2DynTable::new(), transactions: Vec::new(), progress: HTTP2ConnectionState::Http2StateInit, - files: Files::new(), + files: Files::default(), } } pub fn free(&mut self) { self.transactions.clear(); - self.files.free(); } pub fn set_event(&mut self, event: HTTP2Event) { diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index 5869ca770e..32d2277755 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -323,7 +323,7 @@ impl NFSState { requestmap:HashMap::new(), namemap:HashMap::new(), transactions: Vec::new(), - files:Files::new(), + files:Files::default(), ts_chunk_xid:0, tc_chunk_xid:0, ts_chunk_left:0, @@ -350,10 +350,6 @@ impl NFSState { } } - pub fn free(&mut self) { - self.files.free(); - } - pub fn new_tx(&mut self) -> NFSTransaction { let mut tx = NFSTransaction::new(); self.tx_id += 1; @@ -1386,8 +1382,7 @@ pub extern "C" fn rs_nfs_state_new(_orig_state: *mut std::os::raw::c_void, _orig pub extern "C" fn rs_nfs_state_free(state: *mut std::os::raw::c_void) { // Just unbox... SCLogDebug!("freeing state"); - let mut nfs_state: Box = unsafe{transmute(state)}; - nfs_state.free(); + let mut _nfs_state: Box = unsafe{transmute(state)}; } /// C binding parse a NFS TCP request. Returns 1 on success, -1 on failure. diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index 68b850c5e2..17406f6e9e 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -773,7 +773,7 @@ impl SMBState { ssn2vecoffset_map:HashMap::new(), ssn2tree_map:HashMap::new(), ssnguid2vec_map:HashMap::new(), - files: Files::new(), + files: Files::default(), skip_ts:0, skip_tc:0, file_ts_left:0, @@ -800,7 +800,6 @@ impl SMBState { pub fn free(&mut self) { //self._debug_state_stats(); self._debug_tx_stats(); - self.files.free(); } pub fn new_tx(&mut self) -> SMBTransaction { -- 2.47.2