summaryrefslogtreecommitdiffstats
path: root/src/maze.c
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-02 00:16:53 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-02 00:16:53 (EDT)
commit18ed76f4d68ff7b35954a9e4276c29e1ac9362f6 (patch)
tree0a10901f76d9550d9660a244d7d54d2b8b6d0acc /src/maze.c
parentba5f8f180155888d1aee3507c3fe25109e58abb1 (diff)
downloadmazefight-18ed76f4d68ff7b35954a9e4276c29e1ac9362f6.zip
mazefight-18ed76f4d68ff7b35954a9e4276c29e1ac9362f6.tar.gz
mazefight-18ed76f4d68ff7b35954a9e4276c29e1ac9362f6.tar.bz2
maze: Defend against use-after-free
And non-compliant standard C libraries.
Diffstat (limited to 'src/maze.c')
-rw-r--r--src/maze.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/maze.c b/src/maze.c
index cfa010b..3d62485 100644
--- a/src/maze.c
+++ b/src/maze.c
@@ -179,8 +179,18 @@ mf_maze_new(int s, int w, int h)
}
void
-mf_maze_free(struct mf_maze *m)
+mf_maze_destroy(struct mf_maze **m_p)
{
- free(m->walls);
+ struct mf_maze *m;
+
+ if (m_p == NULL || *m_p == NULL) {
+ return;
+ }
+ m = *m_p;
+
+ if (m->walls != NULL) {
+ free(m->walls);
+ }
free(m);
+ m = NULL;
}