From 36f2033d6864a9ac3a48ac7c0a6b3af0139a3e78 Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Wed, 4 Jun 2025 07:22:51 +0200 Subject: [PATCH] Ensure ticker cleanup in watch functions --- clipboard_android.go | 1 + clipboard_darwin.go | 1 + clipboard_ios.go | 1 + clipboard_linux.go | 1 + clipboard_windows.go | 1 + 5 files changed, 5 insertions(+) diff --git a/clipboard_android.go b/clipboard_android.go index c9ce78f..ea1ebfe 100644 --- a/clipboard_android.go +++ b/clipboard_android.go @@ -81,6 +81,7 @@ func watch(ctx context.Context, t Format) <-chan []byte { ti := time.NewTicker(time.Second) last := Read(t) go func() { + defer ti.Stop() for { select { case <-ctx.Done(): diff --git a/clipboard_darwin.go b/clipboard_darwin.go index bcda127..830217d 100644 --- a/clipboard_darwin.go +++ b/clipboard_darwin.go @@ -100,6 +100,7 @@ func watch(ctx context.Context, t Format) <-chan []byte { ti := time.NewTicker(time.Second) lastCount := C.long(C.clipboard_change_count()) go func() { + defer ti.Stop() for { select { case <-ctx.Done(): diff --git a/clipboard_ios.go b/clipboard_ios.go index e027b8c..f1c162f 100644 --- a/clipboard_ios.go +++ b/clipboard_ios.go @@ -59,6 +59,7 @@ func watch(ctx context.Context, t Format) <-chan []byte { ti := time.NewTicker(time.Second) last := Read(t) go func() { + defer ti.Stop() for { select { case <-ctx.Done(): diff --git a/clipboard_linux.go b/clipboard_linux.go index 14ebe95..c516dac 100644 --- a/clipboard_linux.go +++ b/clipboard_linux.go @@ -138,6 +138,7 @@ func watch(ctx context.Context, t Format) <-chan []byte { ti := time.NewTicker(time.Second) last := Read(t) go func() { + defer ti.Stop() for { select { case <-ctx.Done(): diff --git a/clipboard_windows.go b/clipboard_windows.go index bd042cd..77e6440 100644 --- a/clipboard_windows.go +++ b/clipboard_windows.go @@ -404,6 +404,7 @@ func watch(ctx context.Context, t Format) <-chan []byte { go func() { // not sure if we are too slow or the user too fast :) ti := time.NewTicker(time.Second) + defer ti.Stop() cnt, _, _ := getClipboardSequenceNumber.Call() ready <- struct{}{} for {