Skip to content

Commit 5a20222

Browse files
committed
Fix possible null reference if proxy is never started
1 parent 58ca5a9 commit 5a20222

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

TibiaAPI/Network/Connection.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,21 @@ internal void Stop()
301301
_zStream.deflateEnd();
302302
_zStream.inflateEnd();
303303
_httpListener.Close();
304-
_tcpListener.Stop();
305-
_clientSocket.Close();
306-
_serverSocket.Close();
304+
305+
if (_tcpListener != null)
306+
{
307+
_tcpListener.Stop();
308+
}
309+
310+
if (_clientSocket != null)
311+
{
312+
_clientSocket.Close();
313+
}
314+
315+
if (_serverSocket != null)
316+
{
317+
_serverSocket.Close();
318+
}
307319
}
308320
catch (Exception ex)
309321
{
@@ -865,8 +877,16 @@ protected virtual void Dispose(bool disposing)
865877
if (disposing)
866878
{
867879
_httpClient.Dispose();
868-
_clientSocket.Dispose();
869-
_serverSocket.Dispose();
880+
881+
if (_clientSocket != null)
882+
{
883+
_clientSocket.Dispose();
884+
}
885+
886+
if (_serverSocket != null)
887+
{
888+
_serverSocket.Dispose();
889+
}
870890
}
871891

872892
disposedValue = true;

0 commit comments

Comments
 (0)