From 85c89d2616bd51ec81fa1a3e4341ef437c32c059 Mon Sep 17 00:00:00 2001 From: Karan Dev Sapra <47597256+aang114@users.noreply.github.com> Date: Thu, 4 Jul 2024 07:03:21 +0800 Subject: [PATCH] deinit hashmap in DiskMemoryAllocator::deinit() + use testing allocator as hashmap allocator in tests --- src/accountsdb/index.zig | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/accountsdb/index.zig b/src/accountsdb/index.zig index 835956fbe..25c585840 100644 --- a/src/accountsdb/index.zig +++ b/src/accountsdb/index.zig @@ -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 { @@ -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()); @@ -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;