From 71e0554ed2ffe1536f79d2da9218414a6b2b4b9c Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Wed, 8 Jan 2025 22:43:03 +0100 Subject: [PATCH] Fix memory leak when a parent of a sub biome couldn't be found --- src/server/terrain/biomes.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/terrain/biomes.zig b/src/server/terrain/biomes.zig index 6a8ea128..3222680b 100644 --- a/src/server/terrain/biomes.zig +++ b/src/server/terrain/biomes.zig @@ -670,16 +670,16 @@ pub fn finishLoading() void { } var subBiomeIterator = unfinishedSubBiomes.iterator(); while(subBiomeIterator.next()) |subBiomeData| { + const subBiomeDataList = subBiomeData.value_ptr; + defer subBiomeDataList.deinit(main.globalAllocator); const parentBiome = biomesById.get(subBiomeData.key_ptr.*) orelse { std.log.warn("Couldn't find biome with id {s}. Cannot add sub-biomes.", .{subBiomeData.key_ptr.*}); continue; }; - const subBiomeDataList = subBiomeData.value_ptr; for(subBiomeDataList.items) |item| { parentBiome.subBiomeTotalChance += item.chance; } parentBiome.subBiomes = .initFromContext(main.globalAllocator, subBiomeDataList.items); - subBiomeDataList.deinit(main.globalAllocator); } unfinishedSubBiomes.clearAndFree(main.globalAllocator.allocator);