Fixed memory leaks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user