fix a bug of memory leak of kv

in tos_kv_has_key, if an item is found, should kv_item_free it later.
This commit is contained in:
daishengdong
2020-06-18 20:57:17 +08:00
parent 0202c5b5c9
commit 9bedf2ea80

View File

@@ -1294,7 +1294,8 @@ __API__ kv_err_t tos_kv_get(const char *key, void *value_buf, size_t value_buf_s
__API__ int tos_kv_has_key(const char *key)
{
int has_key;
kv_item_t *item;
int has_key = K_FALSE;
if (!key) {
return KV_ERR_INVALID_PARAM;
@@ -1305,7 +1306,11 @@ __API__ int tos_kv_has_key(const char *key)
}
kv_lock();
has_key = kv_item_find(key) ? K_TRUE : K_FALSE;
item = kv_item_find(key);
if (item) {
has_key = K_TRUE;
kv_item_free(item);
}
kv_unlock();
return has_key;