Skip to content

Commit 777a1a9

Browse files
committed
instance: release jit code memory on drop
1 parent dae3b33 commit 777a1a9

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/cow_memory.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,10 @@ impl CowResetMapping {
175175
impl Drop for CowResetMapping {
176176
fn drop(&mut self) {
177177
tracy_full::zone!("CowResetMapping::drop");
178-
unsafe {
179-
rustix::mm::munmap(self.ptr, self.mapping_size).expect("failed to deallocate mapping")
180-
};
181-
unsafe {
182-
rustix::mm::munmap(self.ref_ptr, self.mapping_size)
183-
.expect("failed to deallocate mapping")
184-
};
178+
unsafe { rustix::mm::munmap(self.ptr, self.mapping_size) }
179+
.expect("failed to deallocate mapping");
180+
unsafe { rustix::mm::munmap(self.ref_ptr, self.mapping_size) }
181+
.expect("failed to deallocate mapping");
185182
}
186183
}
187184

src/fuzzer/i2s_patches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ where
243243
'outer: for i in off..len {
244244
let mut size = core::cmp::min(a.len(), len - i);
245245
while size != 0 {
246-
if &a[0..size] == &input.mutator_bytes()[i..i + size] {
246+
if a[0..size] == input.mutator_bytes()[i..i + size] {
247247
input.mutator_bytes_mut()[i..i + size].copy_from_slice(&b[0..size]);
248248
result = MutationResult::Mutated;
249249
break 'outer;
@@ -252,7 +252,7 @@ where
252252
}
253253
size = core::cmp::min(b.len(), len - i);
254254
while size != 0 {
255-
if &b[0..size] == &input.mutator_bytes()[i..i + size] {
255+
if b[0..size] == input.mutator_bytes()[i..i + size] {
256256
input.mutator_bytes_mut()[i..i + size].copy_from_slice(&b[0..size]);
257257
result = MutationResult::Mutated;
258258
break 'outer;

src/jit/instance.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use super::{CompilationOptions, module::TrapKind, vmcontext::VMContext};
88
pub(crate) struct ModuleInstance {
99
pub vmctx: Box<VMContext>,
1010
pub code_size: usize,
11-
#[allow(unused)]
12-
module: JITModule,
11+
module: Option<JITModule>,
1312
export_func_ptrs: HashMap<String, *const u8>,
1413
trap_pc_registry: HashMap<usize, TrapKind>,
1514
options: CompilationOptions,
@@ -26,7 +25,7 @@ impl ModuleInstance {
2625
) -> Self {
2726
Self {
2827
vmctx,
29-
module,
28+
module: Some(module),
3029
export_func_ptrs,
3130
trap_pc_registry,
3231
code_size,
@@ -94,3 +93,12 @@ impl ModuleInstance {
9493
}
9594
}
9695
}
96+
97+
impl Drop for ModuleInstance {
98+
fn drop(&mut self) {
99+
tracy_full::zone!("ModuleInstance::drop");
100+
if let Some(module) = std::mem::take(&mut self.module) {
101+
unsafe { module.free_memory() };
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)