Fix memory leaks
This commit is contained in:
@@ -44,6 +44,7 @@ int mazemaker_solve(mazegrid_t const* maze, maze_path_t* path) {
|
||||
// check to see if we've reached the end
|
||||
if ((x == maze->width - 1) && (y == maze->height - 1)) {
|
||||
path_copy(&top, path);
|
||||
mazemaker_path_free(&top);
|
||||
code = 1;
|
||||
break;
|
||||
}
|
||||
@@ -89,6 +90,9 @@ int mazemaker_solve(mazegrid_t const* maze, maze_path_t* path) {
|
||||
PUSH_PQ(pq, PathPQ, newpath, dist + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// delete old path
|
||||
mazemaker_path_free(&top);
|
||||
}
|
||||
|
||||
// If no path is found, we will run out of new nodes to explore, the queue
|
||||
@@ -103,6 +107,7 @@ int mazemaker_solve(mazegrid_t const* maze, maze_path_t* path) {
|
||||
}
|
||||
FOREACH_PQ_END
|
||||
}
|
||||
FREE_PQ(pq);
|
||||
node_set_free(set);
|
||||
return code;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user