Skip to content
Snippets Groups Projects
Commit 127d9f16 authored by schneider's avatar schneider
Browse files

change(ble): Don't allocate if not needed when resizing

parent e54c19ea
No related branches found
No related tags found
1 merge request!446Initial MicroPython BLE support (GATTS)
...@@ -432,7 +432,11 @@ uint8_t AttsDynResize(uint16_t handle, uint16_t maxLen) ...@@ -432,7 +432,11 @@ uint8_t AttsDynResize(uint16_t handle, uint16_t maxLen)
/* find attribute */ /* find attribute */
if ((pAttr = attsFindByHandle(handle, &pGroup)) != NULL) if ((pAttr = attsFindByHandle(handle, &pGroup)) != NULL)
{ {
/* Allocate a buffer for the value of the attribute */ /* Only alllocate a value if there is a change and if
* it was allocated before. */
if(pAttr->pValue && pAttr->maxLen != maxLen )
{
/* Allocate new buffer for the value of the attribute */
pValue = attsDynAlloc(maxLen); pValue = attsDynAlloc(maxLen);
WSF_ASSERT(pValue); WSF_ASSERT(pValue);
...@@ -441,10 +445,12 @@ uint8_t AttsDynResize(uint16_t handle, uint16_t maxLen) ...@@ -441,10 +445,12 @@ uint8_t AttsDynResize(uint16_t handle, uint16_t maxLen)
return ATT_ERR_MEMORY; return ATT_ERR_MEMORY;
} }
pAttr->maxLen = maxLen;
pAttr->pValue = pValue; pAttr->pValue = pValue;
memset(pValue, 0, maxLen); memset(pValue, 0, maxLen);
} }
pAttr->maxLen = maxLen;
}
/* else attribute not found */ /* else attribute not found */
else else
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment