Skip to content

Commit

Permalink
fixed issues identified by code analyser VS2017
Browse files Browse the repository at this point in the history
  • Loading branch information
gardian12 committed Mar 28, 2019
1 parent c41cb6d commit 4facddc
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
19 changes: 18 additions & 1 deletion KeePassNatMsg/KeePassNatMsgExt.cs
Expand Up @@ -22,7 +22,7 @@

namespace KeePassNatMsg
{
public sealed class KeePassNatMsgExt : Plugin
public sealed class KeePassNatMsgExt : Plugin, IDisposable
{

/// <summary>
Expand Down Expand Up @@ -381,5 +381,22 @@ internal JObject GeneratePassword()
}

public static string GetVersion() => KeePassXcVersion.ToString();

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (disposing)
{
// dispose managed resources
IDisposable disposable = (IDisposable)_listener;
disposable?.Dispose();
}
// free native resources
}
}
}
5 changes: 5 additions & 0 deletions KeePassNatMsg/Protocol/Crypto/Nacl.cs
Expand Up @@ -49,8 +49,13 @@ public class TweetNaCl
public static readonly Int32 SignBytes = 64;


[Serializable]
public class InvalidSignatureException : CryptographicException { }

[Serializable]
public class InvalidCipherTextException : CryptographicException { }

[Serializable]
public class InvalidEncryptionKeypair : CryptographicException { }

/// <summary>
Expand Down
21 changes: 19 additions & 2 deletions KeePassNatMsg/Protocol/Listener/SocketReadState.cs
@@ -1,9 +1,10 @@
using System.Net.Sockets;
using System;
using System.Net.Sockets;
using System.Threading;

namespace KeePassNatMsg.Protocol.Listener
{
internal sealed class SocketReadState
internal sealed class SocketReadState : IDisposable
{
public Socket Socket;
public bool Active;
Expand All @@ -15,5 +16,21 @@ public SocketReadState()
WaitHandle = new ManualResetEventSlim(false);
Active = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (disposing)
{
// dispose managed resources
WaitHandle.Dispose();
}
// free native resources
}
}
}
18 changes: 17 additions & 1 deletion KeePassNatMsg/Protocol/Listener/UdpListener.cs
Expand Up @@ -5,7 +5,7 @@

namespace KeePassNatMsg.Protocol.Listener
{
public sealed class UdpListener
public sealed class UdpListener : IDisposable
{
private readonly Thread _thread;
private UdpClient _client;
Expand Down Expand Up @@ -47,6 +47,22 @@ public void Send(string msg, IPEndPoint ep)
_client.Send(data, data.Length, ep);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (disposing)
{
// dispose managed resources
_client.Close();
}
// free native resources
}

private void Run()
{
_ep = new IPEndPoint(IPAddress.Any, _port);
Expand Down
19 changes: 18 additions & 1 deletion KeePassNatMsg/Protocol/Listener/UnixSocketListener.cs
Expand Up @@ -6,7 +6,7 @@

namespace KeePassNatMsg.Protocol.Listener
{
public class UnixSocketListener : IListener
public class UnixSocketListener : IListener, IDisposable
{
private const string SocketName = "kpxc_server";

Expand Down Expand Up @@ -46,6 +46,23 @@ public void Stop()
DeleteSocketFile();
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (disposing)
{
// dispose managed resources
_socket.Close();
_cts.Dispose();
}
// free native resources
}

private void RunThread()
{
DeleteSocketFile();
Expand Down

0 comments on commit 4facddc

Please sign in to comment.