Skip to content

Commit

Permalink
Report OOM errors in NimBLE callbacks. (#2687)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Jan 6, 2025
1 parent 6a34285 commit 8df35d0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/resources/ble_esp32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,9 @@ ServiceContainer<T>::get_or_create_service(const BleCallbackScope* scope,
// try to recover on OOM.
scope->gc();
service = _new BleServiceResource(group(), type(), uuid, start,end);
if (!service) {
ESP_LOGE("BLE", "OOM while creating service in NimBLE callback");
}
}
if (!service) return null;
group()->register_resource(service);
Expand Down Expand Up @@ -1668,6 +1671,9 @@ BleCharacteristicResource* BleServiceResource::get_or_create_characteristic(
// try to recover on OOM.
scope->gc();
characteristic = _new BleCharacteristicResource(group(), this, uuid, properties, value_handle, def_handle);
if (!characteristic) {
ESP_LOGE("BLE", "OOM while creating characteristic in NimBLE callback");
}
}
if (!characteristic) return null;
group()->register_resource(characteristic);
Expand Down Expand Up @@ -1870,6 +1876,9 @@ BleDescriptorResource* BleCharacteristicResource::get_or_create_descriptor(const
// try to recover on OOM.
scope->gc();
descriptor = _new BleDescriptorResource(group(), this, uuid, handle, properties);
if (!descriptor) {
ESP_LOGE("BLE", "OOM while creating descriptor in NimBLE callback");
}
}
if (!descriptor) return null;
group()->register_resource(descriptor);
Expand Down Expand Up @@ -2179,7 +2188,10 @@ bool BleCharacteristicResource::update_subscription_status(const BleCallbackScop
// try to recover on OOM.
scope.gc();
subscription = _new Subscription(indicate, notify, conn_handle);
if (!subscription) return false;
if (!subscription) {
ESP_LOGE("BLE", "OOM while creating subscription in NimBLE callback");
return false;
}
}

subscriptions_.append(subscription);
Expand Down

0 comments on commit 8df35d0

Please sign in to comment.