Skip to content

Commit f5b5989

Browse files
authored
Merge pull request #11595 from SeppoTakalo/IOTSTOR-944
Check return of BlockDevice::init() in TDBStore.
2 parents c385e14 + 513891d commit f5b5989

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)