Skip to content

Commit f9af08c

Browse files
committed
Add error if allocation of cccd attribute fails
1 parent fa2c363 commit f9af08c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "wsf_types.h"
2424
#include "att_api.h"
2525

26+
#include <new>
27+
2628
namespace ble {
2729
namespace impl {
2830

@@ -593,13 +595,18 @@ ble_error_t GattServer::insert_cccd(
593595
*
594596
* Ownership is passed to the GattCharacteristic
595597
*/
596-
GattAttribute* implicit_cccd = new GattAttribute(
598+
GattAttribute* implicit_cccd = new (std::nothrow) GattAttribute(
597599
CCCD_UUID,
598600
attribute_it->pValue,
599601
*attribute_it->pLen,
600602
attribute_it->maxLen,
601603
false);
602604

605+
if(implicit_cccd == nullptr) {
606+
currentHandle--;
607+
return BLE_ERROR_NO_MEM;
608+
}
609+
603610
implicit_cccd->setHandle(cccds[cccd_cnt].handle);
604611
implicit_cccd->allowRead(true);
605612
implicit_cccd->allowWrite(true);

0 commit comments

Comments
 (0)