From f815027cdfbf9fda9f6141d9bf3a5584d6d7a672 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 6 Feb 2018 11:24:50 +0100 Subject: [PATCH] rust/dns: simplify tx freeing 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 | 37 ++++++++----------------------------- rust/src/nfs/nfs.rs | 10 +++++----- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index 7ca5b1b084..c26bfce24c 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -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) { diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index 739d836674..8ce20bc62f 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -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(); } } -- 2.47.2