device: send: check packet length before freeing element

This commit is contained in:
Jason A. Donenfeld 2019-04-18 23:22:03 +09:00
parent 5811447b38
commit d3dd991e4e

View File

@ -601,6 +601,9 @@ func (peer *Peer) RoutineSequentialSender() {
length := uint64(len(elem.packet)) length := uint64(len(elem.packet))
err := peer.SendBuffer(elem.packet) err := peer.SendBuffer(elem.packet)
if len(elem.packet) != MessageKeepaliveSize {
peer.timersDataSent()
}
device.PutMessageBuffer(elem.buffer) device.PutMessageBuffer(elem.buffer)
device.PutOutboundElement(elem) device.PutOutboundElement(elem)
if err != nil { if err != nil {
@ -609,9 +612,6 @@ func (peer *Peer) RoutineSequentialSender() {
} }
atomic.AddUint64(&peer.stats.txBytes, length) atomic.AddUint64(&peer.stats.txBytes, length)
if len(elem.packet) != MessageKeepaliveSize {
peer.timersDataSent()
}
peer.keepKeyFreshSending() peer.keepKeyFreshSending()
} }
} }