diff --git a/Changelog.md b/Changelog.md index ce31f3b0..7493d8c1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ * Add `PriorityQueue` (#392). * Add support for Weak references (#388). * Clarify difference between `List` and `pure/List` in doc comments (#386). +* Fix memory leak bugs in `List.addRepeat` and `List.removeLast` (#343). ## 1.0.0 diff --git a/src/List.mo b/src/List.mo index 62755632..c9fcd5c1 100644 --- a/src/List.mo +++ b/src/List.mo @@ -162,7 +162,7 @@ module { var cnt = count; while (cnt > 0) { let db_size = data_block_size(list.blockIndex); - if (list.elementIndex == 0 and db_size <= cnt) { + if (list.elementIndex == 0 and db_size <= cnt and list.blocks[list.blockIndex].size() == 0) { list.blocks[list.blockIndex] := VarArray.repeat(?initValue, db_size); cnt -= db_size; list.blockIndex += 1 @@ -470,7 +470,7 @@ module { // Keep one totally empty block when removing if (blockIndex + 2 < list.blocks.size()) { - if (list.blocks[blockIndex + 2].size() == 0) { + if (list.blocks[blockIndex + 2].size() > 0) { list.blocks[blockIndex + 2] := [var] } };