Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.127 diff -u -r1.127 civclient.c --- client/civclient.c 2002/05/03 16:35:07 1.127 +++ client/civclient.c 2002/05/16 17:28:24 @@ -557,10 +557,10 @@ popdown_all_city_dialogs(); close_all_diplomacy_dialogs(); client_remove_all_cli_conn(); - game_remove_all_players(); set_unit_focus_no_center(NULL); clear_notify_window(); - idex_init(); /* clear old data */ + game_free(); + game_init(); } update_menus(); } Index: client/climisc.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v retrieving revision 1.94 diff -u -r1.94 climisc.c --- client/climisc.c 2002/04/27 03:58:36 1.94 +++ client/climisc.c 2002/05/16 17:28:24 @@ -203,7 +203,7 @@ **************************************************************************/ void client_remove_player(int plrno) { - player_free_island_imprs(get_player(plrno), max_cont_used); + game_remove_player(get_player(plrno)); game_renumber_players(plrno); } Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.235 diff -u -r1.235 packhand.c --- client/packhand.c 2002/05/07 07:40:52 1.235 +++ client/packhand.c 2002/05/16 17:28:26 @@ -1800,27 +1800,23 @@ } b = &improvement_types[p->id]; + improvement_free(p->id); + sz_strlcpy(b->name, p->name); b->tech_req = p->tech_req; b->bldg_req = p->bldg_req; - free(b->terr_gate); b->terr_gate = p->terr_gate; /* pointer assignment */ - free(b->spec_gate); b->spec_gate = p->spec_gate; /* pointer assignment */ b->equiv_range = p->equiv_range; - free(b->equiv_dupl); b->equiv_dupl = p->equiv_dupl; /* pointer assignment */ - free(b->equiv_repl); b->equiv_repl = p->equiv_repl; /* pointer assignment */ b->obsolete_by = p->obsolete_by; b->is_wonder = p->is_wonder; b->build_cost = p->build_cost; b->upkeep = p->upkeep; b->sabotage = p->sabotage; - free(b->effect); b->effect = p->effect; /* pointer assignment */ b->variant = p->variant; /* FIXME: remove when gen-impr obsoletes */ - free(b->helptext); b->helptext = p->helptext; /* pointer assignment */ sz_strlcpy(b->soundtag, p->soundtag); sz_strlcpy(b->soundtag_alt, p->soundtag_alt); Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.139 diff -u -r1.139 game.c --- common/game.c 2002/04/30 12:52:54 1.139 +++ common/game.c 2002/05/16 17:28:27 @@ -741,11 +741,11 @@ map_init(); idex_init(); - + conn_list_init(&game.all_connections); conn_list_init(&game.est_connections); conn_list_init(&game.game_connections); - + for(i=0; ieffects); + player_free_island_imprs(pplayer); unit_list_iterate(pplayer->units, punit) game_remove_unit(punit); @@ -1020,6 +1041,7 @@ for (i=oldmax+1; i<=maxcont; i++) { geff_vector_init(&plr->island_effects[i]); } + plr->max_continent = maxcont; } players_iterate_end; } Index: common/game.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.h,v retrieving revision 1.105 diff -u -r1.105 game.h --- common/game.h 2002/04/30 12:52:54 1.105 +++ common/game.h 2002/05/16 17:28:27 @@ -222,6 +222,7 @@ }; void game_init(void); +void game_free(void); int game_next_year(int); void game_advance_year(void); Index: common/idex.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/idex.c,v retrieving revision 1.7 diff -u -r1.7 idex.c --- common/idex.c 2002/02/12 04:49:52 1.7 +++ common/idex.c 2002/05/16 17:28:27 @@ -28,6 +28,7 @@ unless IDEX_DIE set. ***************************************************************************/ +#include #include #include "city.h" @@ -50,20 +51,26 @@ /************************************************************************** Initialize. Should call this at the start before use. - May also call later, to re-initialize (eg, client disconnects). ***************************************************************************/ void idex_init(void) { - if (idex_city_hash) { - hash_free(idex_city_hash); - idex_city_hash = NULL; - } - if (idex_unit_hash) { - hash_free(idex_unit_hash); - idex_unit_hash = NULL; - } + assert(idex_city_hash == NULL); + assert(idex_unit_hash == NULL); + idex_city_hash = hash_new(hash_fval_int, hash_fcmp_int); idex_unit_hash = hash_new(hash_fval_int, hash_fcmp_int); +} + +/************************************************************************** + Free the hashs. +***************************************************************************/ +void idex_free(void) +{ + hash_free(idex_city_hash); + idex_city_hash = NULL; + + hash_free(idex_unit_hash); + idex_unit_hash = NULL; } /************************************************************************** Index: common/idex.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/idex.h,v retrieving revision 1.1 diff -u -r1.1 idex.h --- common/idex.h 2000/04/30 13:15:40 1.1 +++ common/idex.h 2002/05/16 17:28:27 @@ -22,6 +22,7 @@ struct unit; void idex_init(void); +void idex_free(void); void idex_register_city(struct city *pcity); void idex_register_unit(struct unit *punit); Index: common/improvement.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v retrieving revision 1.20 diff -u -r1.20 improvement.c --- common/improvement.c 2002/03/06 03:03:13 1.20 +++ common/improvement.c 2002/05/16 17:28:28 @@ -197,6 +197,32 @@ } /************************************************************************** + Frees the memory associated with this improvement. +**************************************************************************/ +void improvement_free(Impr_Type_id id) +{ + struct impr_type *p = get_improvement_type(id); + + free(p->terr_gate); + p->terr_gate = NULL; + + free(p->spec_gate); + p->spec_gate = NULL; + + free(p->equiv_dupl); + p->equiv_dupl = NULL; + + free(p->equiv_repl); + p->equiv_repl = NULL; + + free(p->effect); + p->effect = NULL; + + free(p->helptext); + p->helptext = NULL; +} + +/************************************************************************** Returns 1 if the improvement_type "exists" in this game, 0 otherwise. An improvement_type doesn't exist if one of: - id is out of range; Index: common/improvement.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/improvement.h,v retrieving revision 1.10 diff -u -r1.10 improvement.h --- common/improvement.h 2002/04/18 09:59:16 1.10 +++ common/improvement.h 2002/05/16 17:28:28 @@ -271,6 +271,7 @@ /* improvement functions */ +void improvement_free(Impr_Type_id id); struct impr_type *get_improvement_type(Impr_Type_id id); bool improvement_exists(Impr_Type_id id); int improvement_value(Impr_Type_id id); Index: common/map.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.c,v retrieving revision 1.119 diff -u -r1.119 map.c --- common/map.c 2002/02/27 08:19:02 1.119 +++ common/map.c 2002/05/16 17:28:29 @@ -205,22 +205,32 @@ /************************************************************************** Allocate space for map, and initialise the tiles. Uses current map.xsize and map.ysize. - Uses fc_realloc, in case map was allocated before (eg, in client); - should have called map_init() (via game_init()) before this, - so map.tiles will be 0 on first call. **************************************************************************/ void map_allocate(void) { freelog(LOG_DEBUG, "map_allocate (was %p) (%d,%d)", map.tiles, map.xsize, map.ysize); - - map.tiles = fc_realloc(map.tiles, map.xsize*map.ysize*sizeof(struct tile)); + + assert(map.tiles == NULL); + map.tiles = fc_malloc(map.xsize * map.ysize * sizeof(struct tile)); whole_map_iterate(x, y) { tile_init(map_get_tile(x, y)); } whole_map_iterate_end; } +/*************************************************************** + Frees the allocated memory of the map. +***************************************************************/ +void map_free(void) +{ + whole_map_iterate(x, y) { + tile_free(map_get_tile(x, y)); + } whole_map_iterate_end; + free(map.tiles); + map.tiles = NULL; +} + /*************************************************************** ... ***************************************************************/ @@ -1134,6 +1144,14 @@ unit_list_init(&ptile->units); ptile->worked = NULL; /* pointer to city working tile */ ptile->assigned = 0; /* bitvector */ +} + +/*************************************************************** +... +***************************************************************/ +void tile_free(struct tile *ptile) +{ + unit_list_unlink_all(&ptile->units); } /*************************************************************** Index: common/map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.125 diff -u -r1.125 map.h --- common/map.h 2002/02/27 10:33:08 1.125 +++ common/map.h 2002/05/16 17:28:29 @@ -183,6 +183,7 @@ bool map_is_empty(void); void map_init(void); void map_allocate(void); +void map_free(void); char *map_get_tile_info_text(int x, int y); char *map_get_tile_fpt_text(int x, int y); @@ -267,6 +268,7 @@ void map_set_special(int x, int y, enum tile_special_type spe); void map_clear_special(int x, int y, enum tile_special_type spe); void tile_init(struct tile *ptile); +void tile_free(struct tile *ptile); bool is_real_tile(int x, int y); bool is_normal_map_pos(int x, int y); Index: common/player.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/player.c,v retrieving revision 1.94 diff -u -r1.94 player.c --- common/player.c 2002/04/05 05:56:49 1.94 +++ common/player.c 2002/05/16 17:28:30 @@ -126,7 +126,7 @@ { int i; - player_free_island_imprs(plr, numcont); + player_free_island_imprs(plr); if (game.num_impr_types>0) { /* Initialise lists of improvements with island-wide equiv_range. */ if (plr->island_improv) @@ -149,7 +149,7 @@ Frees the player's list of island-range improvements and effects. ***************************************************************/ -void player_free_island_imprs(struct player *plr, int numcont) +void player_free_island_imprs(struct player *plr) { int i; @@ -159,11 +159,12 @@ } if (plr->island_effects) { - for (i=0; i<=numcont; i++) { + for (i=0; i<=plr->max_continent; i++) { geff_vector_free(&plr->island_effects[i]); } free(plr->island_effects); plr->island_effects = NULL; + plr->max_continent = 0; } } Index: common/player.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/player.h,v retrieving revision 1.75 diff -u -r1.75 player.h --- common/player.h 2002/03/05 19:13:44 1.75 +++ common/player.h 2002/05/16 17:28:30 @@ -190,6 +190,7 @@ [map.num_continents][game.num_impr_types] */ struct geff_vector effects; /* effects with range==Player */ struct geff_vector *island_effects; /* effects with range==Island */ + int max_continent; struct { int length; @@ -199,7 +200,7 @@ void player_init(struct player *plr); void player_init_island_imprs(struct player *plr, int numcont); -void player_free_island_imprs(struct player *plr, int numcont); +void player_free_island_imprs(struct player *plr); struct player *find_player_by_name(char *name); struct player *find_player_by_name_prefix(const char *name, enum m_pre_result *result); Index: server/plrhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v retrieving revision 1.233 diff -u -r1.233 plrhand.c --- server/plrhand.c 2002/05/07 07:40:54 1.233 +++ server/plrhand.c 2002/05/16 17:28:32 @@ -1344,7 +1344,6 @@ lsend_packet_generic_integer(&game.est_connections, PACKET_REMOVE_PLAYER, &pack); - player_free_island_imprs(pplayer, map.num_continents); game_remove_player(pplayer); game_renumber_players(pplayer->player_no); }