From 3b2975afad5a37ed8d1afe16416ebc82ca31c596 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 5 Feb 2016 14:26:28 -0800 Subject: [PATCH] Fixes Solenoid Memory Leak HAL ports can be freed after solenoid port is created --- WPILib/DoubleSolenoid.cs | 4 ++-- WPILib/Solenoid.cs | 1 + WPILib/SolenoidBase.cs | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/WPILib/DoubleSolenoid.cs b/WPILib/DoubleSolenoid.cs index 3bdb29b8..2ee465ac 100644 --- a/WPILib/DoubleSolenoid.cs +++ b/WPILib/DoubleSolenoid.cs @@ -58,11 +58,11 @@ private void InitSolenoid() IntPtr port = GetPortWithModule((byte)ModuleNumber, (byte)m_forwardChannel); m_forwardSolenoid = InitializeSolenoidPort(port, ref status); CheckStatus(status); - + FreePort(port); port = GetPortWithModule((byte)ModuleNumber, (byte)m_reverseChannel); m_reverseSolenoid = InitializeSolenoidPort(port, ref status); CheckStatus(status); - + FreePort(port); HAL.Base.HAL.Report(ResourceType.kResourceType_Solenoid, (byte)m_forwardChannel, (byte)(ModuleNumber)); HAL.Base.HAL.Report(ResourceType.kResourceType_Solenoid, (byte)m_reverseChannel, (byte)(ModuleNumber)); LiveWindow.LiveWindow.AddActuator("DoubleSolenoid", ModuleNumber, m_forwardChannel, this); diff --git a/WPILib/Solenoid.cs b/WPILib/Solenoid.cs index d6560140..45e89726 100644 --- a/WPILib/Solenoid.cs +++ b/WPILib/Solenoid.cs @@ -40,6 +40,7 @@ private void InitSolenoid() IntPtr port = GetPortWithModule((byte)ModuleNumber, (byte)m_channel); m_solenoidPort = InitializeSolenoidPort(port, ref status); CheckStatus(status); + FreePort(port); LiveWindow.LiveWindow.AddActuator("Solenoid", ModuleNumber, m_channel, this); Report(ResourceType.kResourceType_Solenoid, (byte)m_channel, (byte)ModuleNumber); } diff --git a/WPILib/SolenoidBase.cs b/WPILib/SolenoidBase.cs index 2ed9e650..dcfc9a6a 100644 --- a/WPILib/SolenoidBase.cs +++ b/WPILib/SolenoidBase.cs @@ -33,8 +33,10 @@ protected SolenoidBase(int moduleNumber) { ModuleNumber = moduleNumber; int status = 0; - m_port = InitializeSolenoidPort(GetPortWithModule((byte) ModuleNumber, 0), ref status); + IntPtr port = GetPortWithModule((byte)ModuleNumber, 0); + m_port = InitializeSolenoidPort(port, ref status); CheckStatus(status); + FreePort(port); } }