Skip to content

Commit db166cf

Browse files
author
Seppo Takalo
committed
SecureStore: Deinitialize also member TDBStorages on deinit()
1 parent 5dbf6f9 commit db166cf

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

features/storage/kvstore/securestore/SecureStore.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,21 +797,36 @@ int SecureStore::init()
797797
int SecureStore::deinit()
798798
{
799799
_mutex.lock();
800+
int ret;
800801
if (_is_initialized) {
801-
mbedtls_entropy_free(static_cast<mbedtls_entropy_context *>(_entropy));
802-
delete static_cast<mbedtls_entropy_context *>(_entropy);
803-
delete static_cast<inc_set_handle_t *>(_inc_set_handle);
804-
delete _scratch_buf;
805-
// TODO: Deinit member KVs?
802+
if (_entropy) {
803+
mbedtls_entropy_free(static_cast<mbedtls_entropy_context *>(_entropy));
804+
delete static_cast<mbedtls_entropy_context *>(_entropy);
805+
delete static_cast<inc_set_handle_t *>(_inc_set_handle);
806+
delete _scratch_buf;
807+
_entropy = nullptr;
808+
}
809+
ret = _underlying_kv->deinit();
810+
if (ret) {
811+
goto END;
812+
}
813+
if (_rbp_kv) {
814+
ret = _rbp_kv->deinit();
815+
if (ret) {
816+
goto END;
817+
}
818+
}
806819
}
807820

808821
_is_initialized = false;
809822
#if defined(MBEDTLS_PLATFORM_C)
810823
mbedtls_platform_teardown(NULL);
811824
#endif /* MBEDTLS_PLATFORM_C */
825+
ret = MBED_SUCCESS;
826+
END:
812827
_mutex.unlock();
813828

814-
return MBED_SUCCESS;
829+
return ret;
815830
}
816831

817832

0 commit comments

Comments
 (0)