From 127d9f16eb8e6c27bbb29fb34fcf6391234b56e2 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 24 Jan 2021 17:10:24 +0100 Subject: [PATCH] change(ble): Don't allocate if not needed when resizing --- .../ble-host/sources/stack/att/atts_dyn.c | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) 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 1ce2c877a..f523cf687 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 -- GitLab