aboutsummaryrefslogtreecommitdiff
path: root/device/channels.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-02-09 15:09:50 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-09 15:37:04 +0100
commit6ac1240821207c90708ac205f4f98eb8b82f3ee5 (patch)
tree1331654d522170b1942bfcd1741bcc3b6fb40672 /device/channels.go
parent4b5d15ec2b1f148b4f718ed16d7e7f022b19fe1b (diff)
downloadwireguard-go-6ac1240821207c90708ac205f4f98eb8b82f3ee5.tar.gz
wireguard-go-6ac1240821207c90708ac205f4f98eb8b82f3ee5.zip
device: do not attach finalizer to non-returned object
Before, the code attached a finalizer to an object that wasn't returned, resulting in immediate garbage collection. Instead return the actual pointer. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/channels.go')
-rw-r--r--device/channels.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/device/channels.go b/device/channels.go
index 4bd6090..1e3e206 100644
--- a/device/channels.go
+++ b/device/channels.go
@@ -71,14 +71,15 @@ func newHandshakeQueue() *handshakeQueue {
return q
}
+type autodrainingInboundQueue struct {
+ c chan *QueueInboundElement
+}
+
// newAutodrainingInboundQueue returns a channel that will be drained when it gets GC'd.
// It is useful in cases in which is it hard to manage the lifetime of the channel.
// The returned channel must not be closed. Senders should signal shutdown using
// some other means, such as sending a sentinel nil values.
-func newAutodrainingInboundQueue(device *Device) chan *QueueInboundElement {
- type autodrainingInboundQueue struct {
- c chan *QueueInboundElement
- }
+func newAutodrainingInboundQueue(device *Device) *autodrainingInboundQueue {
q := &autodrainingInboundQueue{
c: make(chan *QueueInboundElement, QueueInboundSize),
}
@@ -97,7 +98,11 @@ func newAutodrainingInboundQueue(device *Device) chan *QueueInboundElement {
}
}
})
- return q.c
+ return q
+}
+
+type autodrainingOutboundQueue struct {
+ c chan *QueueOutboundElement
}
// newAutodrainingOutboundQueue returns a channel that will be drained when it gets GC'd.
@@ -105,10 +110,7 @@ func newAutodrainingInboundQueue(device *Device) chan *QueueInboundElement {
// The returned channel must not be closed. Senders should signal shutdown using
// some other means, such as sending a sentinel nil values.
// All sends to the channel must be best-effort, because there may be no receivers.
-func newAutodrainingOutboundQueue(device *Device) chan *QueueOutboundElement {
- type autodrainingOutboundQueue struct {
- c chan *QueueOutboundElement
- }
+func newAutodrainingOutboundQueue(device *Device) *autodrainingOutboundQueue {
q := &autodrainingOutboundQueue{
c: make(chan *QueueOutboundElement, QueueOutboundSize),
}
@@ -127,5 +129,5 @@ func newAutodrainingOutboundQueue(device *Device) chan *QueueOutboundElement {
}
}
})
- return q.c
+ return q
}