From 7d967e694706978935ef0b27eac375f463d05493 Mon Sep 17 00:00:00 2001 From: Gopal Tiwari Date: Tue, 31 May 2022 13:11:06 +0530 Subject: [PATCH] mesh/appkey: Fix memory leaks While performing the static analysis using the coverity tool found following memory leak reports bluez-5.64/mesh/appkey.c:143: leaked_storage: Variable "key" going out of scope leaks the storage it points to. Error: RESOURCE_LEAK (CWE-772): bluez-5.64/mesh/appkey.c:146: leaked_storage: Variable "key" going out of scope leaks the storage it points to. Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- mesh/appkey.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mesh/appkey.c b/mesh/appkey.c index 167910b..c9450da 100644 --- a/mesh/appkey.c +++ b/mesh/appkey.c @@ -138,11 +138,15 @@ bool appkey_key_init(struct mesh_net *net, uint16_t net_idx, uint16_t app_idx, key->net_idx = net_idx; key->app_idx = app_idx; - if (key_value && !set_key(key, app_idx, key_value, false)) + if (key_value && !set_key(key, app_idx, key_value, false)) { + appkey_key_free(key); return false; + } - if (new_key_value && !set_key(key, app_idx, new_key_value, true)) + if (new_key_value && !set_key(key, app_idx, new_key_value, true)) { + appkey_key_free(key); return false; + } l_queue_push_tail(app_keys, key); -- 2.7.4