Fixed memory leaks

This commit is contained in:
2026-04-08 14:20:17 +02:00
parent fea5a0ea5f
commit a9dd430cc7
3 changed files with 11 additions and 16 deletions

View File

@@ -93,7 +93,7 @@ pub const NodeManager = struct {
}
/// Removes the node from the list with all appropriate checks
pub fn remove(self: *NodeManager, node_to_remove: *Node) !void {
pub fn remove(self: *NodeManager, allocator: std.mem.Allocator, node_to_remove: *Node) !void {
// In case the node has references to the existing roads we can not remove it
// This also means we don't have to deinit it, since it has no elements
if (node_to_remove.roads.items.len > 0) return;
@@ -101,6 +101,7 @@ pub const NodeManager = struct {
for (self.nodes.items, 0..) |*node, i| {
if (node.id != node_to_remove.id) continue;
node.deinit(allocator);
_ = self.nodes.swapRemove(i);
return;
}

View File

@@ -62,6 +62,7 @@ pub const RoadManager = struct {
/// Removes the road which reference is passed in; returns error if the road is invalid
pub fn remove(self: *RoadManager, road_to_remove: *Road) !void {
// todo fix leak
try road_to_remove.unreferenceNodes();
for (self.roads.items, 0..) |*road, i| {