5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 08:20:28 +00:00

Merge pull request #662 from Arceliar/memleak

Fix memory leak
This commit is contained in:
Arceliar 2020-03-09 23:57:15 -05:00 committed by GitHub
commit ea7e074cf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -800,7 +800,7 @@ func (t *switchTable) _handleIdle(port switchPort) bool {
t.queues._cleanup(t)
now := time.Now()
for psize < 65535 {
var best string
var best *string
var bestPriority float64
for streamID, buf := range t.queues.bufs {
// Filter over the streams that this node is closer to
@ -809,22 +809,23 @@ func (t *switchTable) _handleIdle(port switchPort) bool {
coords := switch_getPacketCoords(packet.bytes)
priority := float64(now.Sub(packet.time)) / float64(buf.size)
if priority >= bestPriority && t.portIsCloser(coords, port) {
best = streamID
b := streamID // copy since streamID is mutated in the loop
best = &b
bestPriority = priority
}
}
if best != "" {
buf := t.queues.bufs[best]
if best != nil {
buf := t.queues.bufs[*best]
var packet switch_packetInfo
// TODO decide if this should be LIFO or FIFO
packet, buf.packets = buf.packets[0], buf.packets[1:]
buf.size -= uint64(len(packet.bytes))
t.queues.size -= uint64(len(packet.bytes))
if len(buf.packets) == 0 {
delete(t.queues.bufs, best)
delete(t.queues.bufs, *best)
} else {
// Need to update the map, since buf was retrieved by value
t.queues.bufs[best] = buf
t.queues.bufs[*best] = buf
}
packets = append(packets, packet.bytes)
psize += len(packet.bytes)