Skip to content

Commit c219ca0

Browse files
committed
fix(RemoteChar): Release task on BLE_HS_EDONE only
1 parent bc8da03 commit c219ca0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/NimBLERemoteCharacteristic.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,22 @@ int NimBLERemoteCharacteristic::descriptorDiscCB(
7272
const auto pChr = (NimBLERemoteCharacteristic*)pTaskData->m_pInstance;
7373
const auto uuid = filter->uuid; // UUID to filter for
7474

75-
if (pChr->getHandle() != chrHandle) {
76-
return 0; // Descriptor not for this characteristic
77-
}
78-
// Return early if not the descriptor we are looking for if filter exists
79-
if (rc != 0 || (uuid && ble_uuid_cmp(uuid->getBase(), &dsc->uuid.u))) {
75+
// Error/Done; or
76+
// Wrong characteristic; or
77+
// Descriptor does not match UUID filter
78+
if (rc != 0 || pChr->getHandle() != chrHandle
79+
|| (uuid && ble_uuid_cmp(uuid->getBase(), &dsc->uuid.u))) {
8080
goto Done;
8181
}
82-
83-
rc = !!uuid * BLE_HS_EDONE; // If found the descriptor, stop the search
82+
// Results added until BLE_HS_EDONE is received
8483
pChr->m_vDescriptors.push_back(new NimBLERemoteDescriptor(pChr, dsc));
84+
// Return BLE_HS_EDONE if the descriptor was found, stop the search
85+
rc = !!uuid * BLE_HS_EDONE;
8586

8687
Done:
87-
NimBLEUtils::taskRelease(*pTaskData, rc);
88+
if (rc == BLE_HS_EDONE) {
89+
NimBLEUtils::taskRelease(*pTaskData, rc);
90+
}
8891
NIMBLE_LOGD(LOG_TAG, "<< Descriptor Discovery");
8992
return rc;
9093
}

0 commit comments

Comments
 (0)