Complete.Org: Mailing Lists: Archives: freeciv-dev: November 1998:
[Freeciv-Dev] more wipe(boat,server) problems/fixes
Home

[Freeciv-Dev] more wipe(boat,server) problems/fixes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxxx
Subject: [Freeciv-Dev] more wipe(boat,server) problems/fixes
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sun, 1 Nov 1998 22:17:51 +1100

I came across another case of "the server going down with the boat"
when a boat gets wiped and removing its passengers leaves a 
dangling iterator.

In this case it was in aicity.c:emergency_reallocate_workers(),
when an AI disbanded a boat which was causing unrest.  The boat
had !punit->ai.passenger, so the AI thought it was ok, but it
happened to be on the same square as another boat which did have
passengers, which were removed with the first boat.  One of these
happened to be next in line in the city's unit list, so when it 
was freed the iterator link was pointing at freed memory, etc.

This patch does the following, to fix this particular problem and
to help with this sort of problem in general:

To fix the direct problem (the segfault) there are now functions
wipe_unit_safe() and handle_unit_disband_safe() which are passed
an iterator which is advanced past any wiped units.

Also exposed in this case is a second problem, where the passengers
should not be wiped when a boat on their square is lost (eg, disbanded, 
or home city captured) if there is another boat there which can carry 
them.  For this I've implemented transporter_min_cargo_to_unitlist().
(Also, now if a Carrier or Submarine is disbanded, any missles/planes 
on that square survive; they may soon run out of fuel, but they
have a chance to get to safety.)

Also:
- found and fixed another case where a segfault could occur
  in similar circumstances in citytools.c:transfer_city_units()
- used the new functions to simplify (safe) loss of trireme in
  unitfunc.c:player_restore_units()
- fixed a small memory leak in wipe_unit() (now wipe_unit_safe())
  where the cargo list was not unlinked (that is, the memory for
  the genlist nodes themselves).

-- David

Attachment: wipe_safe.diff.gz
Description: GNU Zip compressed data


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] more wipe(boat,server) problems/fixes, David Pfitzner <=