diff --git a/libloadviz/src/bin/stressload.rs b/libloadviz/src/bin/stressload.rs new file mode 100644 index 0000000..a0356a8 --- /dev/null +++ b/libloadviz/src/bin/stressload.rs @@ -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(); + } +} diff --git a/libloadviz/src/system_load.rs b/libloadviz/src/system_load.rs index aeec077..97ae14d 100644 --- a/libloadviz/src/system_load.rs +++ b/libloadviz/src/system_load.rs @@ -35,6 +35,14 @@ pub fn get_load_counters() -> Vec { }); } + unsafe { + libc::vm_deallocate( + libc::mach_task_self(), + cpu_info as libc::vm_address_t, + num_cpu_info.try_into().unwrap(), + ); + } + return load_counters; }