From 513891d4f68b27378b58d18117c558995c4c4eb8 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 30 Sep 2019 11:02:49 +0300 Subject: [PATCH] Check return of BlockDevice::init() in TDBStore. Return value was ignored, and TDBStore:init() ended up in a MBED_ERROR() phase after that. TDBStore API was limited to allow returning of only two separate errors, which may end up hiding the actual return value. Change the documentation slightly to allow returning of original error code from the underlying block device. Fixes #11591 --- features/storage/kvstore/tdbstore/TDBStore.cpp | 18 +++++++++++++++++- features/storage/kvstore/tdbstore/TDBStore.h | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/features/storage/kvstore/tdbstore/TDBStore.cpp b/features/storage/kvstore/tdbstore/TDBStore.cpp index 2f25e1c4d32..73e106a151a 100644 --- a/features/storage/kvstore/tdbstore/TDBStore.cpp +++ b/features/storage/kvstore/tdbstore/TDBStore.cpp @@ -1019,7 +1019,10 @@ int TDBStore::init() _size = (size_t) -1; _buff_bd = new BufferedBlockDevice(_bd); - _buff_bd->init(); + ret = _buff_bd->init(); + if (ret) { + goto fail; + } // Underlying BD must have flash attributes, i.e. have an erase value if (_bd->get_erase_value() == -1) { @@ -1140,6 +1143,19 @@ int TDBStore::init() _is_initialized = true; _mutex.unlock(); return ret; +fail: + delete[] ram_table; + delete _buff_bd; + delete[] _work_buf; + delete[] _key_buf; + delete reinterpret_cast(_inc_set_handle); + _ram_table = nullptr; + _buff_bd = nullptr; + _work_buf = nullptr; + _key_buf = nullptr; + _inc_set_handle = nullptr; + _mutex.unlock(); + return ret; } int TDBStore::deinit() diff --git a/features/storage/kvstore/tdbstore/TDBStore.h b/features/storage/kvstore/tdbstore/TDBStore.h index 727ad7c7eb4..d287718edc2 100644 --- a/features/storage/kvstore/tdbstore/TDBStore.h +++ b/features/storage/kvstore/tdbstore/TDBStore.h @@ -61,8 +61,7 @@ class TDBStore : public KVStore { * the available data and clean corrupted and erroneous records. * * @returns MBED_SUCCESS Success. - * MBED_ERROR_READ_FAILED Unable to read from media. - * MBED_ERROR_WRITE_FAILED Unable to write to media. + * @returns Negative error code on failure. */ virtual int init();