Skip to content

Commit

Permalink
Fix NullReferenceException in StartReceive method (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds authored Jan 4, 2021
1 parent 01f0ba7 commit 82f52b2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Tmds.MDns/NetworkInterfaceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ internal void Send(IList<ArraySegment<byte>> packets)
{
try
{
var socket = _socket;
if (socket == null)
{
return;
}
foreach (ArraySegment<byte> segment in packets)
{
_socket.SendTo(segment.Array, segment.Offset, segment.Count, SocketFlags.None, IPv4EndPoint);
socket.SendTo(segment.Array, segment.Offset, segment.Count, SocketFlags.None, IPv4EndPoint);
}
}
catch
Expand Down Expand Up @@ -194,7 +199,7 @@ private void OnReceive(IAsyncResult ar)
lock (this)
{
#if NETSTANDARD1_3
if (args.SocketError != SocketError.Success)
if (args.SocketError != SocketError.Success || _socket == null)
{
return;
}
Expand Down Expand Up @@ -239,7 +244,7 @@ private void OnReceive(IAsyncResult ar)
}
}
}
}
}
if (header.IsResponse && header.IsNoError)
{
for (int i = 0; i < header.QuestionCount; i++)
Expand Down

0 comments on commit 82f52b2

Please sign in to comment.