Skip to content

Commit

Permalink
Fix a memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Oct 3, 2023
1 parent 537f53a commit de907d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libloadviz/src/bin/stressload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! This binary is here to provoke memory leaks in getting the load counters
use std::process;

use libloadviz::system_load::get_load_counters;

fn main() {
println!("PID {} now sleeping for 10s", process::id());
std::thread::sleep(std::time::Duration::from_secs(10));
println!("Now getting load counters");
loop {
get_load_counters();
}
}
8 changes: 8 additions & 0 deletions libloadviz/src/system_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ pub fn get_load_counters() -> Vec<LoadCounters> {
});
}

unsafe {
libc::vm_deallocate(
libc::mach_task_self(),
cpu_info as libc::vm_address_t,
num_cpu_info.try_into().unwrap(),
);
}

return load_counters;
}

Expand Down

0 comments on commit de907d4

Please sign in to comment.