summaryrefslogtreecommitdiffhomepage
path: root/device/allowedips.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-06-04 16:33:28 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-06-04 16:33:28 +0200
commitf9b48a961cd271bcc58c4c76b61a84a139e76167 (patch)
tree7a8f380838ba5844c04e75269e075ddfe373256d /device/allowedips.go
parentd0cf96114fa60b8f7e7a671a7749538edec9d877 (diff)
device: zero out allowedip node pointers when removing
This should make it a bit easier for the garbage collector. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/allowedips.go')
-rw-r--r--device/allowedips.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/device/allowedips.go b/device/allowedips.go
index 95615ab..c08399b 100644
--- a/device/allowedips.go
+++ b/device/allowedips.go
@@ -96,6 +96,14 @@ func (node *trieEntry) maskSelf() {
}
}
+func (node *trieEntry) zeroizePointers() {
+ // Make the garbage collector's life slightly easier
+ node.peer = nil
+ node.child[0] = nil
+ node.child[1] = nil
+ node.parent.parentBit = nil
+}
+
func (node *trieEntry) nodePlacement(ip net.IP, cidr uint8) (parent *trieEntry, exact bool) {
for node != nil && node.cidr <= cidr && commonBits(node.bits, ip) >= node.cidr {
parent = node
@@ -257,10 +265,12 @@ func (table *AllowedIPs) RemoveByPeer(peer *Peer) {
}
*node.parent.parentBit = child
if node.child[0] != nil || node.child[1] != nil || node.parent.parentBitType > 1 {
+ node.zeroizePointers()
continue
}
parent := (*trieEntry)(unsafe.Pointer(uintptr(unsafe.Pointer(node.parent.parentBit)) - unsafe.Offsetof(node.child) - unsafe.Sizeof(node.child[0])*uintptr(node.parent.parentBitType)))
if parent.peer != nil {
+ node.zeroizePointers()
continue
}
child = parent.child[node.parent.parentBitType^1]
@@ -268,6 +278,8 @@ func (table *AllowedIPs) RemoveByPeer(peer *Peer) {
child.parent = parent.parent
}
*parent.parent.parentBit = child
+ node.zeroizePointers()
+ parent.zeroizePointers()
}
}