Skip to content

Commit

Permalink
deinit hashmap in DiskMemoryAllocator::deinit() + use testing allocat…
Browse files Browse the repository at this point in the history
…or as hashmap allocator in tests
  • Loading branch information
aang114 committed Jul 3, 2024
1 parent fb487ce commit 85c89d2
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/accountsdb/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ pub const DiskMemoryAllocator = struct {
if (str_allocator) |a| {
a.free(self.filepath);
}
self.hashmap.deinit();
}

pub fn allocator(self: *Self) std.mem.Allocator {
Expand Down Expand Up @@ -1082,8 +1083,7 @@ pub const DiskMemoryAllocator = struct {
};

test "tests disk allocator on hashmaps" {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var allocator = DiskMemoryAllocator.init("test_data/tmp", gpa.allocator());
var allocator = DiskMemoryAllocator.init("test_data/tmp", std.testing.allocator);
defer allocator.deinit(null);

var refs = std.AutoHashMap(Pubkey, AccountRef).init(allocator.allocator());
Expand All @@ -1100,14 +1100,12 @@ test "tests disk allocator on hashmaps" {
}

test "tests disk allocator" {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var allocator = DiskMemoryAllocator.init("test_data/tmp", gpa.allocator());
var allocator = DiskMemoryAllocator.init("test_data/tmp", std.testing.allocator);

var disk_account_refs = try ArrayList(AccountRef).initCapacity(
allocator.allocator(),
1,
);
defer disk_account_refs.deinit();

var ref = AccountRef.default();
ref.location.Cache.index = 2;
Expand Down

0 comments on commit 85c89d2

Please sign in to comment.