Merge pull request #11595 from SeppoTakalo/IOTSTOR-944

Check return of BlockDevice::init() in TDBStore.
pull/11618/head
Martin Kojtal 2019-10-01 11:33:39 +02:00 committed by GitHub
commit f5b5989fc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -1019,7 +1019,10 @@ int TDBStore::init()
_size = (size_t) -1; _size = (size_t) -1;
_buff_bd = new BufferedBlockDevice(_bd); _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 // Underlying BD must have flash attributes, i.e. have an erase value
if (_bd->get_erase_value() == -1) { if (_bd->get_erase_value() == -1) {
@ -1140,6 +1143,19 @@ end:
_is_initialized = true; _is_initialized = true;
_mutex.unlock(); _mutex.unlock();
return ret; return ret;
fail:
delete[] ram_table;
delete _buff_bd;
delete[] _work_buf;
delete[] _key_buf;
delete reinterpret_cast<inc_set_handle_t *>(_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() int TDBStore::deinit()

View File

@ -61,8 +61,7 @@ public:
* the available data and clean corrupted and erroneous records. * the available data and clean corrupted and erroneous records.
* *
* @returns MBED_SUCCESS Success. * @returns MBED_SUCCESS Success.
* MBED_ERROR_READ_FAILED Unable to read from media. * @returns Negative error code on failure.
* MBED_ERROR_WRITE_FAILED Unable to write to media.
*/ */
virtual int init(); virtual int init();