From 9b14870e5c6ed12074f33186b662b92e65b68f22 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 22 Dec 2015 15:49:12 +0000 Subject: [PATCH 1/2] Fix shutdown of Gap instance to avoid NULL refs --- source/nRF5xn.cpp | 6 ++---- source/nRF5xn.h | 20 +++++--------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/source/nRF5xn.cpp b/source/nRF5xn.cpp index 9aa3749..cb074f8 100644 --- a/source/nRF5xn.cpp +++ b/source/nRF5xn.cpp @@ -53,8 +53,7 @@ nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId) nRF5xn::nRF5xn(void) : initialized(false), instanceID(BLE::DEFAULT_INSTANCE), - _gapInstance(), - gapInstance(NULL), + gapInstance(), gattServerInstance(NULL), gattClientInstance(NULL), securityManagerInstance(NULL) @@ -193,8 +192,7 @@ ble_error_t nRF5xn::shutdown(void) } #endif - /* Gap instance is always present */ - error = gapInstance->reset(); + error = gapInstance.reset(); if (error != BLE_ERROR_NONE) { return error; } diff --git a/source/nRF5xn.h b/source/nRF5xn.h index c0a65f3..819faea 100644 --- a/source/nRF5xn.h +++ b/source/nRF5xn.h @@ -53,10 +53,7 @@ public: * statically. */ virtual Gap &getGap() { - if (gapInstance == NULL) { - gapInstance = &_gapInstance; - } - return *gapInstance; + return gapInstance; }; /** @@ -116,10 +113,7 @@ public: * internal pointer has been declared mutable. */ virtual const Gap &getGap() const { - if (gapInstance == NULL) { - gapInstance = &_gapInstance; - } - return *gapInstance; + return gapInstance; }; /** @@ -166,15 +160,11 @@ private: BLE::InstanceID_t instanceID; private: - mutable nRF5xGap _gapInstance; /**< Gap instance whose reference is returned from a call to - * getGap(). Unlike the GattClient, GattServer and - * SecurityManager, Gap is always needed in a BLE application. */ + mutable nRF5xGap gapInstance; /**< Gap instance whose reference is returned from a call to + * getGap(). Unlike the GattClient, GattServer and + * SecurityManager, Gap is always needed in a BLE application. */ private: - mutable nRF5xGap *gapInstance; /**< Pointer to the Gap object instance. - * If NULL, then Gap has not been initialized. - * The pointer has been declared as 'mutable' so that - * it can be assigned inside a 'const' function. */ mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance. * If NULL, then GattServer has not been initialized. * The pointer has been declared as 'mutable' so that From 22082c54ae5ebb7f75b3eec43b3573bf3316a4ef Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 22 Dec 2015 15:51:34 +0000 Subject: [PATCH 2/2] Add minor comment in shutdown function --- source/nRF5xn.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/nRF5xn.cpp b/source/nRF5xn.cpp index cb074f8..edfa54b 100644 --- a/source/nRF5xn.cpp +++ b/source/nRF5xn.cpp @@ -192,6 +192,7 @@ ble_error_t nRF5xn::shutdown(void) } #endif + /* Gap instance is always present */ error = gapInstance.reset(); if (error != BLE_ERROR_NONE) { return error;