Merge branch 'bugfix/nvs_leaks' into 'master'
nvs: fix memory leaks in HashList and nvs_close Fixes TW8162. Associated test case is run under Instruments on macOS, until I set up valgrind to test this automatically on Linux. See merge request !150
This commit is contained in:
@@ -116,6 +116,7 @@ extern "C" void nvs_close(nvs_handle handle)
|
||||
return;
|
||||
}
|
||||
s_nvs_handles.erase(it);
|
||||
delete static_cast<HandleEntry*>(it);
|
||||
}
|
||||
|
||||
extern "C" esp_err_t nvs_erase_key(nvs_handle handle, const char* key)
|
||||
|
||||
@@ -17,7 +17,11 @@
|
||||
namespace nvs
|
||||
{
|
||||
|
||||
HashList::~HashList()
|
||||
HashList::HashList()
|
||||
{
|
||||
}
|
||||
|
||||
void HashList::clear()
|
||||
{
|
||||
for (auto it = mBlockList.begin(); it != mBlockList.end();) {
|
||||
auto tmp = it;
|
||||
@@ -26,6 +30,11 @@ HashList::~HashList()
|
||||
delete static_cast<HashListBlock*>(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
HashList::~HashList()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
HashList::HashListBlock::HashListBlock()
|
||||
{
|
||||
|
||||
@@ -25,11 +25,18 @@ namespace nvs
|
||||
class HashList
|
||||
{
|
||||
public:
|
||||
HashList();
|
||||
~HashList();
|
||||
|
||||
void insert(const Item& item, size_t index);
|
||||
void erase(const size_t index);
|
||||
size_t find(size_t start, const Item& item);
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
HashList(const HashList& other);
|
||||
const HashList& operator= (const HashList& rhs);
|
||||
|
||||
protected:
|
||||
|
||||
struct HashListNode {
|
||||
@@ -57,7 +64,6 @@ protected:
|
||||
HashListNode mNodes[ENTRY_COUNT];
|
||||
};
|
||||
|
||||
|
||||
typedef intrusive_list<HashListBlock> TBlockList;
|
||||
TBlockList mBlockList;
|
||||
}; // class HashList
|
||||
|
||||
@@ -744,7 +744,7 @@ esp_err_t Page::erase()
|
||||
mFirstUsedEntry = INVALID_ENTRY;
|
||||
mNextFreeEntry = INVALID_ENTRY;
|
||||
mState = PageState::UNINITIALIZED;
|
||||
mHashList = HashList();
|
||||
mHashList.clear();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user