Skip to content

Commit

Permalink
Fixes Solenoid Memory Leak
Browse files Browse the repository at this point in the history
HAL ports can be freed after solenoid port is created
  • Loading branch information
ThadHouse committed Feb 5, 2016
1 parent 06bbdc1 commit 3b2975a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions WPILib/DoubleSolenoid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions WPILib/Solenoid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion WPILib/SolenoidBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 3b2975a

Please sign in to comment.