mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Free new game_state properly in Mosaic's execute_move()
Using sfree() rather than free_game() in the error paths meant that various arrays referenced from the game_state weren't properly freed. Also one error path didn't free the game_state at all.
This commit is contained in:
8
mosaic.c
8
mosaic.c
@ -1282,8 +1282,10 @@ static game_state *execute_move(const game_state *state, const char *move)
|
|||||||
move_params[i] = atoi(p);
|
move_params[i] = atoi(p);
|
||||||
while (*p && isdigit((unsigned char)*p)) p++;
|
while (*p && isdigit((unsigned char)*p)) p++;
|
||||||
if (i+1 < nparams) {
|
if (i+1 < nparams) {
|
||||||
if (*p != ',')
|
if (*p != ',') {
|
||||||
|
free_game(new_state);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1299,7 +1301,7 @@ static game_state *execute_move(const game_state *state, const char *move)
|
|||||||
}
|
}
|
||||||
cell = get_coords(new_state, new_state->cells_contents, x, y);
|
cell = get_coords(new_state, new_state->cells_contents, x, y);
|
||||||
if (cell == NULL) {
|
if (cell == NULL) {
|
||||||
sfree(new_state);
|
free_game(new_state);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (*cell >= STATE_OK_NUM) {
|
if (*cell >= STATE_OK_NUM) {
|
||||||
@ -1369,7 +1371,7 @@ static game_state *execute_move(const game_state *state, const char *move)
|
|||||||
cell = get_coords(new_state, new_state->cells_contents,
|
cell = get_coords(new_state, new_state->cells_contents,
|
||||||
x + (dirX * i), y + (dirY * i));
|
x + (dirX * i), y + (dirY * i));
|
||||||
if (cell == NULL) {
|
if (cell == NULL) {
|
||||||
sfree(new_state);
|
free_game(new_state);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ((*cell & STATE_OK_NUM) == 0) {
|
if ((*cell & STATE_OK_NUM) == 0) {
|
||||||
|
Reference in New Issue
Block a user