files: construct with default, free on drop

Update protocols.
pull/6197/head
Victor Julien 4 years ago
parent d757545f03
commit 3587033d9e

@ -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(),

@ -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) {

@ -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.

@ -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 {

Loading…
Cancel
Save