diff options
author | P. 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) |
commit | 18ed76f4d68ff7b35954a9e4276c29e1ac9362f6 (patch) | |
tree | 0a10901f76d9550d9660a244d7d54d2b8b6d0acc | |
parent | ba5f8f180155888d1aee3507c3fe25109e58abb1 (diff) | |
download | mazefight-18ed76f4d68ff7b35954a9e4276c29e1ac9362f6.zip mazefight-18ed76f4d68ff7b35954a9e4276c29e1ac9362f6.tar.gz mazefight-18ed76f4d68ff7b35954a9e4276c29e1ac9362f6.tar.bz2 |
maze: Defend against use-after-free
And non-compliant standard C libraries.
-rw-r--r-- | src/maze.c | 14 | ||||
-rw-r--r-- | src/maze.h | 2 |
2 files changed, 13 insertions, 3 deletions
@@ -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; } @@ -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_ */ |