Skip to content

Check return of BlockDevice::init() in TDBStore. #11595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion features/storage/kvstore/tdbstore/TDBStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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_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()
Expand Down
3 changes: 1 addition & 2 deletions features/storage/kvstore/tdbstore/TDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down