]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
files: construct with default, free on drop
authorVictor Julien <victor@inliniac.net>
Mon, 7 Jun 2021 11:29:11 +0000 (13:29 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 11 Jun 2021 12:43:41 +0000 (14:43 +0200)
Update protocols.

rust/src/filecontainer.rs
rust/src/http2/http2.rs
rust/src/nfs/nfs.rs
rust/src/smb/smb.rs

index 9e01502b73ce4a5c25f7b9b686977722df27853b..d61d2461644be6101b323dfc4300bce5d2a0244f 100644 (file)
@@ -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(),
index e3bd02cc4b585a720e1615367e6729d52e725bce..fe09c60a7e30d243b39ac7147f5f9659bf91090f 100644 (file)
@@ -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) {
index 5869ca770e6f13f466eb16abd050bfc049dbb522..32d227775532e1e68cc5d46065d63968e4e03eb7 100644 (file)
@@ -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<NFSState> = unsafe{transmute(state)};
-    nfs_state.free();
+    let mut _nfs_state: Box<NFSState> = unsafe{transmute(state)};
 }
 
 /// C binding parse a NFS TCP request. Returns 1 on success, -1 on failure.
index 68b850c5e256cb143235aed80cc7b8d44c736907..17406f6e9e879a6a5f752c7fede57361f48185c7 100644 (file)
@@ -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 {