summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-07-05 01:40:12 -0400
committerGitHub <noreply@github.com>2023-07-05 01:40:12 -0400
commita10b91239bfd46bc4216e5aa27099e8511ca1dfd (patch)
tree10b9a797d6d880498d4d4b5c6a6a2b1e69434b6c /src
parentf21ffde0684e52a1403ef50cddd96bbbcf904ae0 (diff)
bug: missing windows syscall to close the handle on drop when killing (#1245)
* bug: missing windows syscall to close the handle on drop when killing * changelog * fix
Diffstat (limited to 'src')
-rw-r--r--src/app/process_killer.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index 862b17c2..aac85639 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -2,7 +2,7 @@
#[cfg(target_os = "windows")]
use windows::Win32::{
- Foundation::HANDLE,
+ Foundation::{CloseHandle, HANDLE},
System::Threading::{
OpenProcess, TerminateProcess, PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE,
},
@@ -27,7 +27,7 @@ impl Process {
}
fn kill(self) -> Result<(), String> {
- // SAFETY: Windows API call, tread carefully with the args.
+ // SAFETY: Windows API call, this is safe as we are passing in the handle.
let result = unsafe { TerminateProcess(self.0, 1) };
if result.0 == 0 {
return Err("process may have already been terminated.".to_string());
@@ -37,6 +37,16 @@ impl Process {
}
}
+#[cfg(target_os = "windows")]
+impl Drop for Process {
+ fn drop(&mut self) {
+ // SAFETY: Windows API call, this is safe as we are passing in the handle.
+ unsafe {
+ CloseHandle(self.0);
+ }
+ }
+}
+
/// Kills a process, given a PID, for windows.
#[cfg(target_os = "windows")]
pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> {