diff --git a/features/storage/kvstore/tdbstore/TDBStore.cpp b/features/storage/kvstore/tdbstore/TDBStore.cpp index 2f25e1c4d3..73e106a151 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 @@ end: _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 727ad7c7eb..d287718edc 100644 --- a/features/storage/kvstore/tdbstore/TDBStore.h +++ b/features/storage/kvstore/tdbstore/TDBStore.h @@ -61,8 +61,7 @@ public: * 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();