navigate march: Plug memory leaks

When the player aborts the command at the movement prompt, or declines
to abandon a sector, unit_move() returns without freeing the list.
Found with valgrind.  Broken in commit 24000b4 and commit 7c1b166,
both v4.3.33.

Free the list on these returns, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2015-09-20 15:24:22 +02:00
parent 25c7d3798b
commit 1abd3c5b0b
2 changed files with 14 additions and 3 deletions

View file

@ -406,8 +406,13 @@ unit_move(struct emp_qelem *list)
*/
if (!*cp) {
cp = unit_move_getpath(list, suppress_map, path);
if (!cp)
if (!cp) {
if (type == EF_SHIP)
shp_nav_put(list, player->cnum);
else
lnd_mar_put(list, player->cnum);
return RET_FAIL;
}
cp = unit_move_route(leader, path, sizeof(path));
if (!cp || !*cp)
cp = "h";
@ -418,13 +423,17 @@ unit_move(struct emp_qelem *list)
stopping = shp_nav_dir(list, dir, player->cnum)
|| shp_nav_gauntlet(list, 1, player->cnum);
else {
if (!moved && !lnd_abandon_askyn(list))
if (!moved && !lnd_abandon_askyn(list)) {
lnd_mar_put(list, player->cnum);
return RET_FAIL;
}
stopping = lnd_mar_dir(list, dir, player->cnum)
|| lnd_mar_gauntlet(list, 1, player->cnum);
}
if (dir == DIR_STOP)
if (dir == DIR_STOP) {
CANT_HAPPEN(!QEMPTY(list));
return RET_OK;
}
moved = 1;
if (stopping)
cp = "";

View file

@ -1013,6 +1013,8 @@
Play#1 output Play#1 1 Leader is cav cavalry #78
Play#1 output Play#1 4 Do you really want to abandon 3,7 [yn]?
Play#1 input n
Play#1 output Play#1 1 cav cavalry #78 stopped at 3,7
Play#1 output Play#1 1 cav cavalry #79 stopped at 3,7
Play#1 output Play#1 1 command failed
Play#1 output Play#1 6 0 567
Play#1 input march 84/83/80/81/82