From 95520c067a6b4d5483933b29922c60a01529fcde Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Sat, 25 Mar 2023 02:58:01 +0800 Subject: [PATCH] [kvs] fix kvs leak (#25814) --- src/platform/Ameba/KeyValueStoreManagerImpl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp index 520766f3746f31..897f42c167202f 100644 --- a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp +++ b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp @@ -91,6 +91,15 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, return (err = CHIP_ERROR_INVALID_ARGUMENT); } + if (checkExist(key, key)) + { + ret = deleteKey(key, key); + if (TRUE != ret) + { + ChipLogError(DeviceLayer, "Warning, KVS leakage, failed to remove old kvs value"); + } + } + ret = setPref_new(key, key, (uint8_t *) value, value_size); if (TRUE == ret)