summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/maze.c14
-rw-r--r--src/maze.h2
2 files changed, 13 insertions, 3 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;
}
diff --git a/src/maze.h b/src/maze.h
index 1f22702..c584c35 100644
--- a/src/maze.h
+++ b/src/maze.h
@@ -33,6 +33,6 @@ struct mf_maze *
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);
#endif /* MF_MAZE_H_ */