Skip to content

Commit

Permalink
mblk leak replace_headers (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzezeski committed May 28, 2022
1 parent 0d27014 commit 1245055
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions illumos-ddi-dki/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ extern "C" {
pub fn ddi_soft_state_fini(state_p: *mut *mut c_void);
pub fn ddi_soft_state_zalloc(state: *mut c_void, item: c_int) -> c_int;

pub fn freeb(mp: *mut mblk_t);
pub fn freemsg(mp: *mut mblk_t);

pub fn gethrtime() -> hrtime_t;
Expand Down
15 changes: 15 additions & 0 deletions opte/src/engine/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,9 @@ impl Packet<Parsed> {
self.state.body.pkt_offset -= seg.len;
self.state.body.seg_index -= 1;
seg.nullify_cont();
// This segment has become an orphan and therefore must be
// freed manually.
PacketSeg::free(seg);
}

assert_eq!(self.state.body.seg_index, 0);
Expand Down Expand Up @@ -1644,6 +1647,18 @@ pub struct PacketSeg {
}

impl PacketSeg {
fn free(self) {
cfg_if! {
if #[cfg(all(not(feature = "std"), not(test)))] {
// Safety: We know the mblk wrapped by PacketSeg is legit
// and came from the system's allocb(9F).
unsafe { ddi::freeb(self.unwrap()) };
} else {
mock_freeb(self.unwrap());
}
}
}

fn link(&mut self, seg: &PacketSeg) {
unsafe { (*self.mp).b_cont = seg.mp };
}
Expand Down

0 comments on commit 1245055

Please sign in to comment.