Fix sockets not cleaning up, leading to a file descriptor leak

This commit is contained in:
Ilya Zlobintsev 2021-03-07 07:04:46 +02:00
parent d76b23a248
commit 862a46d754

View File

@ -1,3 +1,5 @@
use nix::unistd;
use crate::config::Config;
use crate::gpu_controller::{FanControlInfo, GpuStats};
use crate::gpu_controller::{GpuInfo, PowerProfile};
@ -50,6 +52,11 @@ impl DaemonConnection {
}
}
}
nix::sys::socket::shutdown(socket, nix::sys::socket::Shutdown::Both)
.expect("Could not shut down");
nix::unistd::close(socket).expect("Failed to close");
let result: Result<DaemonResponse, DaemonResponse> =
bincode::deserialize(&buffer).expect("failed to deserialize message");
@ -80,6 +87,11 @@ impl DaemonConnection {
let buffer = Daemon::read_buffer(socket);
nix::sys::socket::shutdown(socket, nix::sys::socket::Shutdown::Both)
.expect("Failed to shut down");
nix::unistd::close(socket).expect("Failed to close");
bincode::deserialize(&buffer).expect("failed to deserialize message")
}