Skip to content

Commit 80ef52f

Browse files
committed
Make sure to join the child
1 parent 117cf0b commit 80ef52f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

crates/flycheck/src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use std::{
66
fmt,
77
io::{self, BufReader},
8+
ops,
89
path::PathBuf,
9-
process::{Command, Stdio},
10+
process::{self, Command, Stdio},
1011
time::Duration,
1112
};
1213

@@ -236,8 +237,9 @@ fn run_cargo(
236237
mut command: Command,
237238
on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool,
238239
) -> io::Result<()> {
239-
let mut child =
240+
let child =
240241
command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()).spawn()?;
242+
let mut child = ChildKiller(child);
241243

242244
// We manually read a line at a time, instead of using serde's
243245
// stream deserializers, because the deserializer cannot recover
@@ -283,3 +285,24 @@ fn run_cargo(
283285

284286
Ok(())
285287
}
288+
289+
struct ChildKiller(process::Child);
290+
291+
impl ops::Deref for ChildKiller {
292+
type Target = process::Child;
293+
fn deref(&self) -> &process::Child {
294+
&self.0
295+
}
296+
}
297+
298+
impl ops::DerefMut for ChildKiller {
299+
fn deref_mut(&mut self) -> &mut process::Child {
300+
&mut self.0
301+
}
302+
}
303+
304+
impl Drop for ChildKiller {
305+
fn drop(&mut self) {
306+
let _ = self.0.kill();
307+
}
308+
}

0 commit comments

Comments
 (0)