From b2bb9b3d2a5ae82315ccdd68c9e0ba0acdb984e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 24 Aug 2022 18:54:02 +0800 Subject: [PATCH] Fix early close --- monitor_shared.go | 4 +++- monitor_windows.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/monitor_shared.go b/monitor_shared.go index cf451b4..eeef602 100644 --- a/monitor_shared.go +++ b/monitor_shared.go @@ -68,7 +68,9 @@ func (m *defaultInterfaceMonitor) delayCheckUpdate() error { } func (m *defaultInterfaceMonitor) Close() error { - m.networkMonitor.UnregisterCallback(m.element) + if m.element != nil { + m.networkMonitor.UnregisterCallback(m.element) + } return nil } diff --git a/monitor_windows.go b/monitor_windows.go index 7d81742..7e8a566 100644 --- a/monitor_windows.go +++ b/monitor_windows.go @@ -45,10 +45,15 @@ func (m *networkUpdateMonitor) Start() error { } func (m *networkUpdateMonitor) Close() error { - return E.Errors( - m.routeListener.Unregister(), - m.interfaceListener.Unregister(), - ) + if m.routeListener != nil { + m.routeListener.Unregister() + m.routeListener = nil + } + if m.interfaceListener != nil { + m.interfaceListener.Unregister() + m.interfaceListener = nil + } + return nil } func (m *defaultInterfaceMonitor) checkUpdate() error {