Skip to content

Commit 6b0cb07

Browse files
PavelVPVrlubos
authored andcommitted
[nrf fromtree] bluetooth: host: gatt: destroy key after hash calc completes
To generate the GATT Database Hash characteristic, the function `db_hash_setup` is called. It allocates an entry for the AES key that will be used in the CMAC calculation. Next, `db_hash_update` is called to feed all GATT database entries into the hash. Finally, `db_hash_finish` produces the resulting hash. However, the AES key entry allocated in `db_hash_setup` was not being destroyed after the hash generation completed. This caused a memory leak, eventually leading to the error `PSA_ERROR_INSUFFICIENT_MEMORY` (`-134`). This commit fixes the issue by destroying the allocated AES key after the GATT Database Hash calculation is complete, by calling `psa_destroy_key` in `db_hash_finish`. Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit bcdd74d815c4e1c8a3b40d05f071d552790e435f)
1 parent f940b64 commit 6b0cb07

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static int db_hash_finish(struct gen_hash_state *state)
755755
size_t mac_length;
756756
psa_status_t ret = psa_mac_sign_finish(&(state->operation), db_hash.hash, 16, &mac_length);
757757

758+
psa_destroy_key(state->key);
759+
758760
if (ret != PSA_SUCCESS) {
759761
LOG_ERR("CMAC finish failed %d", ret);
760762
return -EIO;

0 commit comments

Comments
 (0)