From 1df06f459aa506ee3c60ef3b58bd5e5e5e4622c0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 4 Mar 2020 22:39:44 +0000 Subject: [PATCH] avoid duplicated udpbuffer free that may still happen --- OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 4 +--- OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | 3 +-- OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | 6 +++++- .../ClientStack/Linden/UDP/UnackedPacketCollection.cs | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 83f5c4f4e9..0810071b4c 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -4831,11 +4831,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP // because we are requeuing the list of updates. They will be resent in new packets // with the most recent state and priority. m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber); - if(oPacket.Buffer == null) + if (oPacket.Buffer == null) return; - m_udpClient.FreeUDPBuffer(oPacket.Buffer); - // Count this as a resent packet since we are going to requeue all of the updates contained in it Interlocked.Increment(ref m_udpClient.PacketsResent); diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index b09ab9e9ce..414bbd4008 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -1188,8 +1188,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP SyncSend(buffer); // Keep track of when this packet was sent out (right now) - int enow = Environment.TickCount & Int32.MaxValue; - Interlocked.Exchange(ref outgoingPacket.TickCount, enow); + Interlocked.Exchange(ref outgoingPacket.TickCount, Environment.TickCount & Int32.MaxValue); if (outgoingPacket.UnackedMethod == null) FreeUDPBuffer(buffer); diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index 8b2f84f04a..a5d12d1c2f 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs @@ -192,6 +192,7 @@ namespace OpenMetaverse m_udpBuffersPool[m_udpBuffersPoolPtr] = null; m_udpBuffersPoolPtr--; buf.RemoteEndPoint = remoteEndpoint; + buf.DataLength = 0; return buf; } } @@ -202,10 +203,13 @@ namespace OpenMetaverse { lock (m_udpBuffersPoolLock) { + if(buf.DataLength < 0) + return; // avoid duplicated free that may still happen + if (m_udpBuffersPoolPtr < 999) { buf.RemoteEndPoint = null; - buf.DataLength = 0; + buf.DataLength = -1; m_udpBuffersPoolPtr++; m_udpBuffersPool[m_udpBuffersPoolPtr] = buf; } diff --git a/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs index af5b2ae425..db937021df 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs @@ -215,7 +215,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (m_packets.TryGetValue(pendingRemove, out OutgoingPacket removedPacket)) { m_packets.Remove(pendingRemove); - if (removedPacket != null) + if (removedPacket != null && removedPacket.Buffer != null) { // Update stats Interlocked.Add(ref removedPacket.Client.UnackedBytes, -removedPacket.Buffer.DataLength);