diff --git a/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/att/atts_dyn.c b/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/att/atts_dyn.c index 1ce2c877a3162acc847d8ce5b4ec115f3ada1840..f523cf687575f9a68c22fd2e092dfda239c7b0e6 100644 --- a/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/att/atts_dyn.c +++ b/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/att/atts_dyn.c @@ -432,18 +432,24 @@ uint8_t AttsDynResize(uint16_t handle, uint16_t maxLen) /* find attribute */ if ((pAttr = attsFindByHandle(handle, &pGroup)) != NULL) { - /* Allocate a buffer for the value of the attribute */ - pValue = attsDynAlloc(maxLen); - WSF_ASSERT(pValue); - - if (pValue == NULL) + /* Only alllocate a value if there is a change and if + * it was allocated before. */ + if(pAttr->pValue && pAttr->maxLen != maxLen ) { - return ATT_ERR_MEMORY; + /* Allocate new buffer for the value of the attribute */ + pValue = attsDynAlloc(maxLen); + WSF_ASSERT(pValue); + + if (pValue == NULL) + { + return ATT_ERR_MEMORY; + } + + pAttr->pValue = pValue; + memset(pValue, 0, maxLen); } pAttr->maxLen = maxLen; - pAttr->pValue = pValue; - memset(pValue, 0, maxLen); } /* else attribute not found */ else