Fix crash when retrieving descriptors.

If more than one descriptor is found the task would be released beofore the process completed causing a race condition.
This commit is contained in:
h2zero 2025-01-06 15:21:55 -07:00
parent fa468d360a
commit 0b543d9f62
2 changed files with 6 additions and 8 deletions

View file

@ -72,14 +72,8 @@ int NimBLERemoteCharacteristic::descriptorDiscCB(
const auto pChr = (NimBLERemoteCharacteristic*)pTaskData->m_pInstance; const auto pChr = (NimBLERemoteCharacteristic*)pTaskData->m_pInstance;
const NimBLEUUID* uuidFilter = filter->uuid; const NimBLEUUID* uuidFilter = filter->uuid;
if (error->status == BLE_HS_ENOTCONN) {
NIMBLE_LOGE(LOG_TAG, "<< Descriptor Discovery; Not connected");
NimBLEUtils::taskRelease(*pTaskData, error->status);
return error->status;
}
if (pChr->getHandle() != chr_val_handle) { if (pChr->getHandle() != chr_val_handle) {
rc = BLE_HS_EDONE; // descriptor not for this characteristic return 0; // Descriptor not for this characteristic
} }
if (rc == 0) { if (rc == 0) {
@ -92,6 +86,7 @@ int NimBLERemoteCharacteristic::descriptorDiscCB(
} }
pChr->m_vDescriptors.push_back(new NimBLERemoteDescriptor(pChr, dsc)); pChr->m_vDescriptors.push_back(new NimBLERemoteDescriptor(pChr, dsc));
return 0;
} }
NimBLEUtils::taskRelease(*pTaskData, rc); NimBLEUtils::taskRelease(*pTaskData, rc);

View file

@ -147,7 +147,10 @@ int NimBLERemoteService::characteristicDiscCB(uint16_t conn_handle,
const ble_gatt_error* error, const ble_gatt_error* error,
const ble_gatt_chr* chr, const ble_gatt_chr* chr,
void* arg) { void* arg) {
NIMBLE_LOGD(LOG_TAG, "Characteristic Discovery >>"); NIMBLE_LOGD(LOG_TAG,
"Characteristic Discovery >> status: %d handle: %d",
error->status,
(error->status == 0) ? chr->def_handle : -1);
auto pTaskData = (NimBLETaskData*)arg; auto pTaskData = (NimBLETaskData*)arg;
const auto pSvc = (NimBLERemoteService*)pTaskData->m_pInstance; const auto pSvc = (NimBLERemoteService*)pTaskData->m_pInstance;