Skip to content

Commit

Permalink
UnixAgent: fix exception in StopUnixSocket
Browse files Browse the repository at this point in the history
If UnixAgent.StopUnixSocket is called without haveing ever started, we would get a null reference exception.
  • Loading branch information
dlech committed May 24, 2022
1 parent 0724a5d commit 8475d22
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SshAgentLib/UnixAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ public void StartUnixSocket(string socketPath)

public void StopUnixSocket()
{
if (listener == null) {
return;
}

// work around mono bug. listener.Dispose() should delete file, but it
// fails because there are null chars appended to the end of the filename
// for some reason.
// See: https://bugzilla.xamarin.com/show_bug.cgi?id=35004
var socketPath = ((UnixEndPoint)listener.LocalEndpoint).Filename;
var nullTerminatorIndex = socketPath.IndexOf('\0');
listener.Dispose();

if (nullTerminatorIndex > 0)
{
try
Expand Down

0 comments on commit 8475d22

Please sign in to comment.