Quick fix for UDP server memory leak

Related to issue #388.
This commit is contained in:
Travis Nickles 2018-08-12 01:06:02 -05:00
parent f7bffb2f2f
commit 3353b803c3

View File

@ -177,6 +177,7 @@ namespace DS4Windows
SocketAsyncEventArgs args = new SocketAsyncEventArgs(); SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = clientEP; args.RemoteEndPoint = clientEP;
args.SetBuffer(packetData, 0, packetData.Length); args.SetBuffer(packetData, 0, packetData.Length);
args.Completed += ClearSentData;
try { udpSock.SendToAsync(args); } try { udpSock.SendToAsync(args); }
catch (Exception e) { } catch (Exception e) { }
} }
@ -634,6 +635,7 @@ namespace DS4Windows
SocketAsyncEventArgs args = new SocketAsyncEventArgs(); SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = cl; args.RemoteEndPoint = cl;
args.SetBuffer(outputData, 0, outputData.Length); args.SetBuffer(outputData, 0, outputData.Length);
args.Completed += ClearSentData;
try { udpSock.SendToAsync(args); } try { udpSock.SendToAsync(args); }
catch (SocketException ex) { } catch (SocketException ex) { }
} }
@ -642,5 +644,11 @@ namespace DS4Windows
clientsList.Clear(); clientsList.Clear();
clientsList = null; clientsList = null;
} }
private void ClearSentData(object sender, SocketAsyncEventArgs args)
{
args.Dispose();
args = null;
}
} }
} }