]> git.ipfire.org Git - people/ms/suricata.git/blobdiff - rust/src/http2/http2.rs
range: prevents memory leak of file from HTTP2
[people/ms/suricata.git] / rust / src / http2 / http2.rs
index 5bdc0b2af6024203e6889602407575d0e3b6ed8f..37232c84910f541d20e88af819b9b682a968ec58 100644 (file)
@@ -183,6 +183,7 @@ impl HTTP2Transaction {
                         0,
                     );
                     (c.HttpRangeFreeBlock)(self.file_range);
+                    self.file_range = std::ptr::null_mut();
                 }
             }
         }
@@ -426,6 +427,26 @@ impl HTTP2State {
     }
 
     pub fn free(&mut self) {
+        // this should be in HTTP2Transaction::free
+        // but we need state's file container cf https://redmine.openinfosecfoundation.org/issues/4444
+        for tx in &mut self.transactions {
+            if !tx.file_range.is_null() {
+                match unsafe { SC } {
+                    None => panic!("BUG no suricata_config"),
+                    Some(c) => {
+                        (c.HTPFileCloseHandleRange)(
+                            &mut self.files.files_tc,
+                            0,
+                            tx.file_range,
+                            std::ptr::null_mut(),
+                            0,
+                        );
+                        (c.HttpRangeFreeBlock)(tx.file_range);
+                        tx.file_range = std::ptr::null_mut();
+                    }
+                }
+            }
+        }
         self.transactions.clear();
     }
 
@@ -445,7 +466,7 @@ impl HTTP2State {
         let mut found = false;
         let mut index = 0;
         for i in 0..len {
-            let tx = &self.transactions[i];
+            let tx = &mut self.transactions[i];
             if tx.tx_id == tx_id + 1 {
                 found = true;
                 index = i;
@@ -463,6 +484,7 @@ impl HTTP2State {
                                 0,
                             );
                             (c.HttpRangeFreeBlock)(tx.file_range);
+                            tx.file_range = std::ptr::null_mut();
                         }
                     }
                 }