diff --git a/ports/servoshell/build.rs b/ports/servoshell/build.rs index cdedf953519..c401016201e 100644 --- a/ports/servoshell/build.rs +++ b/ports/servoshell/build.rs @@ -56,6 +56,7 @@ fn main() -> Result<(), Box> { #[cfg(not(windows))] panic!("Cross-compiling to windows is currently not supported"); } else if target_os == "macos" { + println!("cargo:rerun-if-changed=platform/macos/count_threads.c"); cc::Build::new() .file("platform/macos/count_threads.c") .compile("count_threads"); diff --git a/ports/servoshell/platform/macos/count_threads.c b/ports/servoshell/platform/macos/count_threads.c index bc3328d278d..cd03ee63677 100644 --- a/ports/servoshell/platform/macos/count_threads.c +++ b/ports/servoshell/platform/macos/count_threads.c @@ -8,6 +8,13 @@ int macos_count_running_threads() { task_t task = current_task(); thread_act_array_t threads; mach_msg_type_number_t tcnt; - task_threads(task, &threads, &tcnt); + const kern_return_t status = task_threads(task, &threads, &tcnt); + if (status == KERN_SUCCESS) { + // Free data structures attached to the thread list. + for (uint32_t t = 0; t < tcnt; t++) { + mach_port_deallocate(task, threads[t]); + } + vm_deallocate(task, (vm_address_t)threads, sizeof(thread_t) * tcnt); + } return tcnt; }