summaryrefslogtreecommitdiffstats
path: root/device/receive.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2020-12-04 15:36:21 -0800
committerJosh Bleecher Snyder <josh@tailscale.com>2020-12-08 14:25:02 -0800
commitd3ff2d6b62b095f37582affe84e267d7e5be88c6 (patch)
tree9d97ec1ba73e2d7024bc3593c29c679763ad62c1 /device/receive.go
parentdevice: use labeled for loop instead of goto (diff)
downloadwireguard-go-d3ff2d6b62b095f37582affe84e267d7e5be88c6.tar.xz
wireguard-go-d3ff2d6b62b095f37582affe84e267d7e5be88c6.zip
device: clear pointers when returning elems to pools
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/receive.go')
-rw-r--r--device/receive.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/device/receive.go b/device/receive.go
index e4a94b5..0a8228c 100644
--- a/device/receive.go
+++ b/device/receive.go
@@ -37,6 +37,17 @@ type QueueInboundElement struct {
endpoint conn.Endpoint
}
+// clearPointers clears elem fields that contain pointers.
+// This makes the garbage collector's life easier and
+// avoids accidentally keeping other objects around unnecessarily.
+// It also reduces the possible collateral damage from use-after-free bugs.
+func (elem *QueueInboundElement) clearPointers() {
+ elem.buffer = nil
+ elem.packet = nil
+ elem.keypair = nil
+ elem.endpoint = nil
+}
+
func (elem *QueueInboundElement) Drop() {
atomic.StoreInt32(&elem.dropped, AtomicTrue)
}