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 {