mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
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.
This commit is contained in:
@ -1020,7 +1020,7 @@ static game_state *execute_move(const game_state *state, const char *move)
|
|||||||
for (i = 0; i < wh && move[i]; ++i)
|
for (i = 0; i < wh && move[i]; ++i)
|
||||||
ret->borders[i] =
|
ret->borders[i] =
|
||||||
(move[i] & BORDER_MASK) | DISABLED(~move[i] & BORDER_MASK);
|
(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;
|
ret->cheated = ret->completed = true;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1036,7 +1036,7 @@ static game_state *execute_move(const game_state *state, const char *move)
|
|||||||
ret->borders[y*w + x] ^= flag;
|
ret->borders[y*w + x] ^= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*move) return NULL; /* leaks `ret', then we die */
|
if (*move) goto badmove;
|
||||||
|
|
||||||
if (!ret->completed)
|
if (!ret->completed)
|
||||||
ret->completed = is_solved(&ret->shared->params, ret->shared->clues,
|
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;
|
return ret;
|
||||||
|
|
||||||
badmove:
|
badmove:
|
||||||
sfree(ret);
|
free_game(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user