aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-12 21:00:22 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commit38cf1955e5861f67d385ede006c5b5d1701aca8d (patch)
tree7209f7602cb3fbc693d38d738a9d76d61224b147
parentc2eedeedfe3c48f3f013fb1308f61d7ef94e8b2c (diff)
downloadpuzzles-38cf1955e5861f67d385ede006c5b5d1701aca8d.zip
puzzles-38cf1955e5861f67d385ede006c5b5d1701aca8d.tar.gz
puzzles-38cf1955e5861f67d385ede006c5b5d1701aca8d.tar.bz2
puzzles-38cf1955e5861f67d385ede006c5b5d1701aca8d.tar.xz
Palisade: don't leak memory on a bad move
Invalid moves can turn up in corrupted save files, and puzzles shouldn't leak memory when failing to load a corrupted save file.
-rw-r--r--palisade.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/palisade.c b/palisade.c
index 865cfd8..036ab1f 100644
--- a/palisade.c
+++ b/palisade.c
@@ -1020,7 +1020,7 @@ static game_state *execute_move(const game_state *state, const char *move)
for (i = 0; i < wh && move[i]; ++i)
ret->borders[i] =
(move[i] & BORDER_MASK) | DISABLED(~move[i] & BORDER_MASK);
- if (i < wh || move[i]) return NULL; /* leaks `ret', then we die */
+ if (i < wh || move[i]) goto badmove;
ret->cheated = ret->completed = true;
return ret;
}
@@ -1036,7 +1036,7 @@ static game_state *execute_move(const game_state *state, const char *move)
ret->borders[y*w + x] ^= flag;
}
- if (*move) return NULL; /* leaks `ret', then we die */
+ if (*move) goto badmove;
if (!ret->completed)
ret->completed = is_solved(&ret->shared->params, ret->shared->clues,
@@ -1045,7 +1045,7 @@ static game_state *execute_move(const game_state *state, const char *move)
return ret;
badmove:
- sfree(ret);
+ free_game(ret);
return NULL;
}