From f23c780eee9c085a5675075075ba6c2a55ff6ffb Mon Sep 17 00:00:00 2001 From: evilsocket Date: Thu, 21 Mar 2019 10:57:16 +0100 Subject: [PATCH] fix: fixed a bug in ble.recon which sometimes caused a crash if ble.recon off was called but no device was present --- modules/ble/ble_recon.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/ble/ble_recon.go b/modules/ble/ble_recon.go index d6a5cddd..b44c7746 100644 --- a/modules/ble/ble_recon.go +++ b/modules/ble/ble_recon.go @@ -173,18 +173,20 @@ func (mod *BLERecon) Start() error { <-mod.quit - mod.Info("stopping scan ...") + if mod.gattDevice != nil { + mod.Info("stopping scan ...") - if mod.currDevice != nil && mod.currDevice.Device != nil && mod.gattDevice != nil { - mod.Debug("resetting connection with %v", mod.currDevice.Device) - mod.gattDevice.CancelConnection(mod.currDevice.Device) - } + if mod.currDevice != nil && mod.currDevice.Device != nil { + mod.Debug("resetting connection with %v", mod.currDevice.Device) + mod.gattDevice.CancelConnection(mod.currDevice.Device) + } - mod.Debug("stopping device") - if err := mod.gattDevice.Stop(); err != nil { - mod.Warning("error while stopping device: %v", err) - } else { - mod.Debug("gatt device closed") + mod.Debug("stopping device") + if err := mod.gattDevice.Stop(); err != nil { + mod.Warning("error while stopping device: %v", err) + } else { + mod.Debug("gatt device closed") + } } mod.done <- true