From 862a46d754959964137f8f8c4d561c2effe2da83 Mon Sep 17 00:00:00 2001 From: Ilya Zlobintsev Date: Sun, 7 Mar 2021 07:04:46 +0200 Subject: [PATCH] Fix sockets not cleaning up, leading to a file descriptor leak --- daemon/src/daemon_connection.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/daemon/src/daemon_connection.rs b/daemon/src/daemon_connection.rs index 0d96cda..00d5025 100644 --- a/daemon/src/daemon_connection.rs +++ b/daemon/src/daemon_connection.rs @@ -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 = 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") }