summaryrefslogtreecommitdiffhomepage
path: root/device/send.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/send.go
parent01d3aaa7f418dd0ca86643ddcc8c82544cb8398b (diff)
device: clear pointers when returning elems to pools
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/send.go')
-rw-r--r--device/send.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/device/send.go b/device/send.go
index fa4da0e..cb3e3f6 100644
--- a/device/send.go
+++ b/device/send.go
@@ -58,9 +58,19 @@ func (device *Device) NewOutboundElement() *QueueOutboundElement {
elem.buffer = device.GetMessageBuffer()
elem.Mutex = sync.Mutex{}
elem.nonce = 0
+ // keypair and peer were cleared (if necessary) by clearPointers.
+ return elem
+}
+
+// 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 *QueueOutboundElement) clearPointers() {
+ elem.buffer = nil
+ elem.packet = nil
elem.keypair = nil
elem.peer = nil
- return elem
}
func (elem *QueueOutboundElement) Drop() {