From bc177fe5ced31a0ba78b1de3818544124bd51303 Mon Sep 17 00:00:00 2001 From: "David A. Baer" Date: Sat, 29 Jan 2022 10:42:00 -0500 Subject: [PATCH] Fix memory leaks --- CMakeLists.txt | 2 +- lib/path.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bdc079..4d5fcbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.0) cmake_policy(VERSION 3.0) -project (mazemaker VERSION 2.0) +project (mazemaker VERSION 2.1) SET(EXEC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Installation prefix for executables and object code libraries" FORCE) SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation prefix for C header files" FORCE) diff --git a/lib/path.c b/lib/path.c index e8ec9c8..bb56343 100644 --- a/lib/path.c +++ b/lib/path.c @@ -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; }