From 8cb0da0597022a670219b351fa3a5f320083a0a5 Mon Sep 17 00:00:00 2001 From: exrok Date: Sat, 20 Dec 2025 19:46:40 +0000 Subject: [PATCH] fix(alsa): Don't leak alsactl process This bug was found when alsactl was repeatedly failing due to a missing device causing a number of alsactl processes to be running. This PR uses tokio's kill_on_drop and an added the process handle to a field in the device. I have not checked the rest of the code base for similar issues but at least after this PR alsa is fixed. :) --- src/blocks/sound/alsa.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/blocks/sound/alsa.rs b/src/blocks/sound/alsa.rs index fd3467615f..efd2f18dc5 100644 --- a/src/blocks/sound/alsa.rs +++ b/src/blocks/sound/alsa.rs @@ -12,23 +12,32 @@ pub(super) struct Device { volume: u32, muted: bool, monitor: ChildStdout, + #[expect( + dead_code, + reason = "Only used in drop to trigger kill and reap of child process" + )] + process: tokio::process::Child, } impl Device { pub(super) fn new(name: String, device: String, natural_mapping: bool) -> Result { + let mut process = Command::new("alsactl") + .arg("monitor") + .kill_on_drop(true) + .stdout(Stdio::piped()) + .spawn() + .error("Failed to start alsactl monitor")?; Ok(Device { name, device, natural_mapping, volume: 0, muted: false, - monitor: Command::new("alsactl") - .arg("monitor") - .stdout(Stdio::piped()) - .spawn() - .error("Failed to start alsactl monitor")? + monitor: process .stdout + .take() .error("Failed to pipe alsactl monitor output")?, + process, }) } }