Add error if allocation of cccd attribute fails

pull/13729/head
George Beckstein 2020-10-09 09:47:05 -04:00
parent fa2c3633dd
commit f9af08c0ad
1 changed files with 8 additions and 1 deletions

View File

@ -23,6 +23,8 @@
#include "wsf_types.h" #include "wsf_types.h"
#include "att_api.h" #include "att_api.h"
#include <new>
namespace ble { namespace ble {
namespace impl { namespace impl {
@ -593,13 +595,18 @@ ble_error_t GattServer::insert_cccd(
* *
* Ownership is passed to the GattCharacteristic * Ownership is passed to the GattCharacteristic
*/ */
GattAttribute* implicit_cccd = new GattAttribute( GattAttribute* implicit_cccd = new (std::nothrow) GattAttribute(
CCCD_UUID, CCCD_UUID,
attribute_it->pValue, attribute_it->pValue,
*attribute_it->pLen, *attribute_it->pLen,
attribute_it->maxLen, attribute_it->maxLen,
false); false);
if(implicit_cccd == nullptr) {
currentHandle--;
return BLE_ERROR_NO_MEM;
}
implicit_cccd->setHandle(cccds[cccd_cnt].handle); implicit_cccd->setHandle(cccds[cccd_cnt].handle);
implicit_cccd->allowRead(true); implicit_cccd->allowRead(true);
implicit_cccd->allowWrite(true); implicit_cccd->allowWrite(true);