]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
rust/dns: simplify tx freeing
authorVictor Julien <victor@inliniac.net>
Tue, 6 Feb 2018 10:24:50 +0000 (11:24 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 6 Feb 2018 20:32:10 +0000 (21:32 +0100)
Now that we no longer need the state when freeing a TX, we can simply
do cleanup from the Drop trait.

rust/src/dns/dns.rs
rust/src/nfs/nfs.rs

index 7ca5b1b0848479d8b628044cabf7275af9079ff3..c26bfce24cc7cbe2fe420b11b14710f9447cc03c 100644 (file)
@@ -205,6 +205,12 @@ impl DNSTransaction {
         if self.events != std::ptr::null_mut() {
             core::sc_app_layer_decoder_events_free_events(&mut self.events);
         }
+        match self.de_state {
+            Some(state) => {
+                core::sc_detect_engine_state_free(state);
+            }
+            None => { },
+        }
     }
 
     /// Get the DNS transactions ID (not the internal tracking ID).
@@ -278,15 +284,6 @@ impl DNSState {
         };
     }
 
-    pub fn free(&mut self) {
-        SCLogDebug!("Freeing {} transactions left in state.",
-                    self.transactions.len());
-        while self.transactions.len() > 0 {
-            self.free_tx_at_index(0);
-        }
-        assert!(self.transactions.len() == 0);
-    }
-
     pub fn new_tx(&mut self) -> DNSTransaction {
         let mut tx = DNSTransaction::new();
         self.tx_id += 1;
@@ -308,17 +305,7 @@ impl DNSState {
             }
         }
         if found {
-            self.free_tx_at_index(index);
-        }
-    }
-
-    fn free_tx_at_index(&mut self, index: usize) {
-        let tx = self.transactions.remove(index);
-        match tx.de_state {
-            Some(state) => {
-                core::sc_detect_engine_state_free(state);
-            }
-            _ => {}
+            self.transactions.remove(index);
         }
     }
 
@@ -335,7 +322,7 @@ impl DNSState {
                 return;
             }
             SCLogDebug!("Purging DNS TX with ID {}", self.transactions[0].id);
-            self.free_tx_at_index(0);
+            self.transactions.remove(0);
         }
     }
 
@@ -533,14 +520,6 @@ impl DNSState {
     }
 }
 
-/// Implement Drop for DNSState as transactions need to do some
-/// explicit cleanup.
-impl Drop for DNSState {
-    fn drop(&mut self) {
-        self.free();
-    }
-}
-
 /// Probe input to see if it looks like DNS.
 fn probe(input: &[u8]) -> bool {
     match parser::dns_parse_request(input) {
index 739d8366746aacfb88db78ebccd24c30006c9927..8ce20bc62f81a91c363b749673dedc1c5fa40597 100644 (file)
@@ -214,17 +214,17 @@ impl NFSTransaction {
         if self.events != std::ptr::null_mut() {
             sc_app_layer_decoder_events_free_events(&mut self.events);
         }
-    }
-}
-
-impl Drop for NFSTransaction {
-    fn drop(&mut self) {
         match self.de_state {
             Some(state) => {
                 sc_detect_engine_state_free(state);
             }
             _ => {}
         }
+    }
+}
+
+impl Drop for NFSTransaction {
+    fn drop(&mut self) {
         self.free();
     }
 }