From f9af08c0ada99d7fc5187446bfdbc3ad594ef2f9 Mon Sep 17 00:00:00 2001 From: George Beckstein Date: Fri, 9 Oct 2020 09:47:05 -0400 Subject: [PATCH] Add error if allocation of cccd attribute fails --- .../FEATURE_BLE/source/cordio/source/GattServerImpl.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp b/connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp index 00b25d5750..24c8c35805 100644 --- a/connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp +++ b/connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp @@ -23,6 +23,8 @@ #include "wsf_types.h" #include "att_api.h" +#include + namespace ble { namespace impl { @@ -593,13 +595,18 @@ ble_error_t GattServer::insert_cccd( * * Ownership is passed to the GattCharacteristic */ - GattAttribute* implicit_cccd = new GattAttribute( + GattAttribute* implicit_cccd = new (std::nothrow) GattAttribute( CCCD_UUID, attribute_it->pValue, *attribute_it->pLen, attribute_it->maxLen, false); + if(implicit_cccd == nullptr) { + currentHandle--; + return BLE_ERROR_NO_MEM; + } + implicit_cccd->setHandle(cccds[cccd_cnt].handle); implicit_cccd->allowRead(true); implicit_cccd->allowWrite(true);