Skip to content

Commit 513891d

Browse files
author
Seppo Takalo
committed
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
1 parent a1961de commit 513891d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,10 @@ int TDBStore::init()
10191019
_size = (size_t) -1;
10201020

10211021
_buff_bd = new BufferedBlockDevice(_bd);
1022-
_buff_bd->init();
1022+
ret = _buff_bd->init();
1023+
if (ret) {
1024+
goto fail;
1025+
}
10231026

10241027
// Underlying BD must have flash attributes, i.e. have an erase value
10251028
if (_bd->get_erase_value() == -1) {
@@ -1140,6 +1143,19 @@ int TDBStore::init()
11401143
_is_initialized = true;
11411144
_mutex.unlock();
11421145
return ret;
1146+
fail:
1147+
delete[] ram_table;
1148+
delete _buff_bd;
1149+
delete[] _work_buf;
1150+
delete[] _key_buf;
1151+
delete reinterpret_cast<inc_set_handle_t *>(_inc_set_handle);
1152+
_ram_table = nullptr;
1153+
_buff_bd = nullptr;
1154+
_work_buf = nullptr;
1155+
_key_buf = nullptr;
1156+
_inc_set_handle = nullptr;
1157+
_mutex.unlock();
1158+
return ret;
11431159
}
11441160

11451161
int TDBStore::deinit()

features/storage/kvstore/tdbstore/TDBStore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class TDBStore : public KVStore {
6161
* the available data and clean corrupted and erroneous records.
6262
*
6363
* @returns MBED_SUCCESS Success.
64-
* MBED_ERROR_READ_FAILED Unable to read from media.
65-
* MBED_ERROR_WRITE_FAILED Unable to write to media.
64+
* @returns Negative error code on failure.
6665
*/
6766
virtual int init();
6867

0 commit comments

Comments
 (0)