diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2023-02-13 11:21:11 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-02-13 11:21:11 +0000 |
| commit | d577aaecab09506988a657fa257c4d0ab85d0cd6 (patch) | |
| tree | d1c035946ae96e9e0dcef559709c7d7f1d4b0cff /mosaic.c | |
| parent | 1aa67e7a75ac21d15780d6aaab65a2c0f6f65198 (diff) | |
| download | puzzles-d577aaecab09506988a657fa257c4d0ab85d0cd6.zip puzzles-d577aaecab09506988a657fa257c4d0ab85d0cd6.tar.gz puzzles-d577aaecab09506988a657fa257c4d0ab85d0cd6.tar.bz2 puzzles-d577aaecab09506988a657fa257c4d0ab85d0cd6.tar.xz | |
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.
Diffstat (limited to 'mosaic.c')
| -rw-r--r-- | mosaic.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -1282,8 +1282,10 @@ static game_state *execute_move(const game_state *state, const char *move) move_params[i] = atoi(p); while (*p && isdigit((unsigned char)*p)) p++; if (i+1 < nparams) { - if (*p != ',') + if (*p != ',') { + free_game(new_state); return NULL; + } 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); if (cell == NULL) { - sfree(new_state); + free_game(new_state); return NULL; } 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, x + (dirX * i), y + (dirY * i)); if (cell == NULL) { - sfree(new_state); + free_game(new_state); return NULL; } if ((*cell & STATE_OK_NUM) == 0) { |